export function createDatabaseTemplate(name) {
return {
'package.json': `{
"name": "@your-username/${name}",
"version": "1.0.0",
"description": "Database MCP server",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},
"keywords": ["mcp", "smithery", "database"],
"author": "Your Name",
"license": "MIT",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.7.0",
"pg": "^8.11.0"
}
}`,
'index.js': `import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import pg from 'pg';
const { Pool } = pg;
// Initialize database connection
let pool;
// Create a new MCP server
const server = new Server(
{ name: "${name}", version: "1.0.0" },
{
capabilities: {
tools: {
run_query: {
description: "Run SQL query on database",
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "SQL query to execute"
},
params: {
type: "array",
description: "Query parameters",
items: {
type: "string"
}
}
},
required: ["query"]
},
handler: async (params) => {
const { query, params: queryParams = [] } = params;
if (!pool) {
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
return {
error: "Database connection string not provided. Set DATABASE_URL environment variable."
};
}
pool = new Pool({
connectionString
});
}
try {
const result = await pool.query(query, queryParams);
return {
rows: result.rows,
rowCount: result.rowCount
};
} catch (error) {
return {
error: error.message
};
}
}
},
describe_table: {
description: "Describe database table structure",
parameters: {
type: "object",
properties: {
tableName: {
type: "string",
description: "Name of the table to describe"
}
},
required: ["tableName"]
},
handler: async (params) => {
const { tableName } = params;
if (!pool) {
const connectionString = process.env.DATABASE_URL;
if (!connectionString) {
return {
error: "Database connection string not provided. Set DATABASE_URL environment variable."
};
}
pool = new Pool({
connectionString
});
}
try {
const query = \`
SELECT column_name, data_type, is_nullable, column_default
FROM information_schema.columns
WHERE table_name = $1
ORDER BY ordinal_position
\`;
const result = await pool.query(query, [tableName]);
return {
columns: result.rows,
count: result.rowCount
};
} catch (error) {
return {
error: error.message
};
}
}
}
}
}
}
);
// Start the server with stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);
`,
'Dockerfile': `FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "index.js"]
`,
'smithery.yaml': `startCommand:
type: stdio
configSchema:
type: object
properties:
databaseUrl:
type: string
description: PostgreSQL connection string
required: ["databaseUrl"]
commandFunction: |
function generateCommand(config) {
return {
command: "node",
args: ["index.js"],
env: {
DATABASE_URL: config.databaseUrl
}
};
}
`
};
}