export function createWebSearchTemplate(name) {
return {
'package.json': `{
"name": "@your-username/${name}",
"version": "1.0.0",
"description": "Web search MCP server",
"main": "index.js",
"type": "module",
"scripts": {
"start": "node index.js"
},
"keywords": ["mcp", "smithery", "web-search"],
"author": "Your Name",
"license": "MIT",
"dependencies": {
"@modelcontextprotocol/sdk": "^1.7.0",
"node-fetch": "^3.3.2"
}
}`,
'index.js': `import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import fetch from 'node-fetch';
// Create a new MCP server
const server = new Server(
{ name: "${name}", version: "1.0.0" },
{
capabilities: {
tools: {
web_search: {
description: "Search the web",
parameters: {
type: "object",
properties: {
query: {
type: "string",
description: "Search query"
},
limit: {
type: "number",
description: "Maximum number of results"
}
},
required: ["query"]
},
handler: async (params) => {
const { query, limit = 5 } = params;
const apiKey = process.env.SEARCH_API_KEY;
if (!apiKey) {
return {
error: "API key not provided. Set SEARCH_API_KEY environment variable."
};
}
try {
// Implement your search API call here
// This is a placeholder
const response = await fetch(\`https://api.example.com/search?q=\${encodeURIComponent(query)}&limit=\${limit}\`, {
headers: {
'Authorization': \`Bearer \${apiKey}\`
}
});
const data = await response.json();
return {
results: data.results || []
};
} 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:
searchApiKey:
type: string
description: API key for the search service
required: ["searchApiKey"]
commandFunction: |
function generateCommand(config) {
return {
command: "node",
args: ["index.js"],
env: {
SEARCH_API_KEY: config.searchApiKey
}
};
}
`
};
}