Skip to content

Commit 39926c4

Browse files
committed
feat: add stoolap://sql-reference resource for discoverability
The sql-assistant prompt content was not discoverable as a resource. Add stoolap://sql-reference resource exposing the live schema and full SQL reference. Extract shared buildSchemaText() and sqlReference constant to avoid duplication between the resource and prompt.
1 parent 9a80208 commit 39926c4

2 files changed

Lines changed: 65 additions & 46 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,13 @@ For deeper reference (live schema + full function signatures), attach the `sql-a
121121
| URI | Description |
122122
|-----|-------------|
123123
| `stoolap://schema` | Full database schema with all tables, views, columns, indexes, and DDL statements |
124+
| `stoolap://sql-reference` | Live database schema plus complete Stoolap SQL reference: data types, 130+ functions with signatures, operators, joins, indexes, window functions, CTEs, transactions, temporal queries, vector search, and known limitations |
124125

125126
## Prompts
126127

127128
| Prompt | Description |
128129
|--------|-------------|
129-
| `sql-assistant` | Injects the live database schema and a complete Stoolap SQL reference (data types, all 130+ functions with signatures, operators, index types, join types, window functions, CTEs, transactions, EXPLAIN, PRAGMA, and known limitations). Provides deeper detail than the auto-injected instructions. |
130+
| `sql-assistant` | Same content as `stoolap://sql-reference` delivered as an MCP prompt. Use whichever your client supports. |
130131

131132
## SQL Coverage
132133

src/index.ts

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,54 +1159,38 @@ server.resource(
11591159
}
11601160
);
11611161

1162-
// ========================== PROMPTS ==========================
1162+
// ========================== SHARED HELPERS ==========================
11631163

1164-
server.prompt(
1165-
"sql-assistant",
1166-
"Injects live database schema and complete Stoolap SQL reference (all data types, 130+ functions with signatures, all operators, join types, index types, window functions, CTEs, transactions, temporal queries, vector search, and known limitations). Attach to give the model full context.",
1167-
{},
1168-
async () => {
1169-
// Build live schema
1170-
let schemaText = "";
1171-
try {
1172-
const tables = await db.query("SHOW TABLES");
1173-
for (const row of tables) {
1174-
const name = String(Object.values(row)[0]);
1175-
const q = quoteId(name);
1176-
const ddlRows = await db.query(`SHOW CREATE TABLE ${q}`);
1177-
const ddl = ddlRows[0] ? String(Object.values(ddlRows[0])[1] ?? Object.values(ddlRows[0])[0]) : `-- ${name}`;
1178-
const indexRows = await db.query(`SHOW INDEXES FROM ${q}`);
1179-
schemaText += `${ddl};\n`;
1180-
if (indexRows.length > 0) {
1181-
schemaText += `-- Indexes: ${JSON.stringify(indexRows)}\n`;
1182-
}
1183-
schemaText += "\n";
1184-
}
1185-
const views = await db.query("SHOW VIEWS");
1186-
for (const row of views) {
1187-
const name = String(Object.values(row)[0]);
1188-
const ddlRows = await db.query(`SHOW CREATE VIEW ${quoteId(name)}`);
1189-
const ddl = ddlRows[0] ? String(Object.values(ddlRows[0])[1] ?? Object.values(ddlRows[0])[0]) : `-- ${name}`;
1190-
schemaText += `${ddl};\n\n`;
1164+
async function buildSchemaText(): Promise<string> {
1165+
let schemaText = "";
1166+
try {
1167+
const tables = await db.query("SHOW TABLES");
1168+
for (const row of tables) {
1169+
const name = String(Object.values(row)[0]);
1170+
const q = quoteId(name);
1171+
const ddlRows = await db.query(`SHOW CREATE TABLE ${q}`);
1172+
const ddl = ddlRows[0] ? String(Object.values(ddlRows[0])[1] ?? Object.values(ddlRows[0])[0]) : `-- ${name}`;
1173+
const indexRows = await db.query(`SHOW INDEXES FROM ${q}`);
1174+
schemaText += `${ddl};\n`;
1175+
if (indexRows.length > 0) {
1176+
schemaText += `-- Indexes: ${JSON.stringify(indexRows)}\n`;
11911177
}
1192-
} catch {
1193-
schemaText = "(unable to read schema)\n";
1178+
schemaText += "\n";
11941179
}
1180+
const views = await db.query("SHOW VIEWS");
1181+
for (const row of views) {
1182+
const name = String(Object.values(row)[0]);
1183+
const ddlRows = await db.query(`SHOW CREATE VIEW ${quoteId(name)}`);
1184+
const ddl = ddlRows[0] ? String(Object.values(ddlRows[0])[1] ?? Object.values(ddlRows[0])[0]) : `-- ${name}`;
1185+
schemaText += `${ddl};\n\n`;
1186+
}
1187+
} catch {
1188+
schemaText = "(unable to read schema)\n";
1189+
}
1190+
return schemaText;
1191+
}
11951192

1196-
return {
1197-
messages: [
1198-
{
1199-
role: "user" as const,
1200-
content: {
1201-
type: "text" as const,
1202-
text: `You are a SQL expert for a Stoolap database. Below is the live schema followed by the complete SQL reference. Write accurate, optimized queries using only supported features.
1203-
1204-
## Current Database Schema
1205-
1206-
\`\`\`sql
1207-
${schemaText}\`\`\`
1208-
1209-
## Stoolap SQL Reference
1193+
const sqlReference = `## Stoolap SQL Reference
12101194
12111195
### Data Types
12121196
| Type | Description | Notes |
@@ -1392,7 +1376,41 @@ ANALYZE table_name (collect optimizer statistics)
13921376
- Recursive CTEs: max 10,000 iterations
13931377
- GENERATE_SERIES: max 10,000,000 rows per call
13941378
1395-
Use the available MCP tools: query, execute, execute_batch, explain, begin_transaction, transaction_execute, transaction_query, transaction_execute_batch, commit_transaction, rollback_transaction, savepoint, rollback_to_savepoint, release_savepoint, list_tables, list_views, describe_table, show_create_table, show_create_view, show_indexes, get_schema, create_table, create_index, create_view, alter_table, drop, analyze_table, vacuum, pragma, version, list_functions.`,
1379+
Use the available MCP tools: query, execute, execute_batch, explain, begin_transaction, transaction_execute, transaction_query, transaction_execute_batch, commit_transaction, rollback_transaction, savepoint, rollback_to_savepoint, release_savepoint, list_tables, list_views, describe_table, show_create_table, show_create_view, show_indexes, get_schema, create_table, create_index, create_view, alter_table, drop, analyze_table, vacuum, pragma, version, list_functions.`;
1380+
1381+
server.resource(
1382+
"sql-reference",
1383+
"stoolap://sql-reference",
1384+
{ description: "Complete Stoolap SQL reference with live database schema: data types, 130+ functions, operators, joins, indexes, window functions, CTEs, transactions, temporal queries, vector search, and known limitations" },
1385+
async () => {
1386+
const schemaText = await buildSchemaText();
1387+
return {
1388+
contents: [
1389+
{
1390+
uri: "stoolap://sql-reference",
1391+
mimeType: "text/markdown",
1392+
text: `## Current Database Schema\n\n\`\`\`sql\n${schemaText}\`\`\`\n\n${sqlReference}`,
1393+
},
1394+
],
1395+
};
1396+
}
1397+
);
1398+
1399+
// ========================== PROMPTS ==========================
1400+
1401+
server.prompt(
1402+
"sql-assistant",
1403+
"Injects live database schema and complete Stoolap SQL reference (all data types, 130+ functions with signatures, all operators, join types, index types, window functions, CTEs, transactions, temporal queries, vector search, and known limitations). Attach to give the model full context.",
1404+
{},
1405+
async () => {
1406+
const schemaText = await buildSchemaText();
1407+
return {
1408+
messages: [
1409+
{
1410+
role: "user" as const,
1411+
content: {
1412+
type: "text" as const,
1413+
text: `You are a SQL expert for a Stoolap database. Below is the live schema followed by the complete SQL reference. Write accurate, optimized queries using only supported features.\n\n## Current Database Schema\n\n\`\`\`sql\n${schemaText}\`\`\`\n\n${sqlReference}`,
13961414
},
13971415
},
13981416
],

0 commit comments

Comments
 (0)