Skip to content

Commit 53c4b33

Browse files
committed
feat: wire up database definition loader and update related imports
1 parent 6727802 commit 53c4b33

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

.changeset/clear-fans-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mcp-svelte-docs': patch
3+
---
4+
5+
wire up db definition loader

src/db-definition-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let db: Database.Database | null = null;
2424
*/
2525
function initDb(): Database.Database {
2626
if (!db) {
27-
const dbPath = join(__dirname, 'definitions.db');
27+
const dbPath = join(__dirname, '../definitions.db');
2828
db = Database(dbPath, { readonly: true });
2929
}
3030
return db;

src/tools/definition-tools.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
1-
import { dirname, join } from 'node:path';
2-
import { fileURLToPath } from 'node:url';
31
import { McpServer } from 'tmcp';
42
import * as v from 'valibot';
53

64
import {
7-
DefinitionItem,
8-
get_all_identifiers,
9-
get_definition_by_identifier,
10-
load_definitions,
11-
suggest_similar_identifiers,
12-
} from '../definition-loader.js';
13-
14-
// Get the definitions directory path
15-
const __filename = fileURLToPath(import.meta.url);
16-
const __dirname = dirname(__filename);
17-
const definitionsDir = join(__dirname, '../../definitions');
5+
DefinitionItem,
6+
get_all_identifiers,
7+
get_definition_by_identifier,
8+
load_definitions,
9+
suggest_similar_identifiers,
10+
} from '../db-definition-loader.js';
1811

1912
// Load all definitions
2013
let definitions: DefinitionItem[] = [];
@@ -155,11 +148,8 @@ function create_definition_error(
155148
identifier: string,
156149
definitions: DefinitionItem[],
157150
): Error {
158-
const suggestions = suggest_similar_identifiers(
159-
definitions,
160-
identifier,
161-
);
162-
const all_identifiers = get_all_identifiers(definitions);
151+
const suggestions = suggest_similar_identifiers(identifier);
152+
const all_identifiers = get_all_identifiers();
163153

164154
let error_message = `Definition for '${identifier}' not found.`;
165155

@@ -211,10 +201,7 @@ async function definition_handler(args: any) {
211201
);
212202

213203
// Find the definition
214-
const definition = get_definition_by_identifier(
215-
definitions,
216-
identifier,
217-
);
204+
const definition = get_definition_by_identifier(identifier);
218205

219206
if (!definition) {
220207
throw create_definition_error(identifier, definitions);
@@ -294,7 +281,7 @@ export function register_definition_tools(
294281
server: McpServer<any>,
295282
): void {
296283
// Load all definitions
297-
definitions = load_definitions(definitionsDir);
284+
definitions = load_definitions();
298285

299286
if (definitions.length === 0) {
300287
console.warn(
@@ -303,7 +290,7 @@ export function register_definition_tools(
303290
} else {
304291
console.log(
305292
`Loaded ${definitions.length} definitions:`,
306-
get_all_identifiers(definitions),
293+
get_all_identifiers(),
307294
);
308295
}
309296

0 commit comments

Comments
 (0)