Only one template for now

This commit is contained in:
Justin Spahr-Summers 2024-11-18 13:28:59 +00:00
commit 76295f6b2f
No known key found for this signature in database
6 changed files with 2 additions and 2 deletions

View file

@ -12,7 +12,7 @@
},
"files": [
"build",
"templates"
"template"
],
"scripts": {
"build": "tsc && shx chmod +x build/index.js",

View file

@ -41,7 +41,7 @@ async function createServer(directory: string, options: any = {}) {
await fs.mkdir(directory, { recursive: true });
// Copy template files
const templateDir = path.join(__dirname, "../templates");
const templateDir = path.join(__dirname, "../template");
const files = await fs.readdir(templateDir, { recursive: true });
for (const file of files) {

3
template/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
node_modules/
build/
*.log

18
template/package.json.ejs Normal file
View file

@ -0,0 +1,18 @@
{
"name": "<%= name %>",
"version": "0.1.0",
"description": "<%= description %>",
"type": "module",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"start": "node build/index.js"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^0.5.0"
},
"devDependencies": {
"@types/node": "^20.11.24",
"typescript": "^5.3.3"
}
}

63
template/src/index.ts.ejs Normal file
View file

@ -0,0 +1,63 @@
#!/usr/bin/env node
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
ListResourcesRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
const server = new Server(
{
name: "<%= name %>",
version: "0.1.0",
},
{
capabilities: {
resources: {},
tools: {},
},
},
);
server.setRequestHandler(ListResourcesRequestSchema, async () => {
return {
resources: [
{
uri: "example://hello",
mimeType: "text/plain",
name: "Example resource",
},
],
};
});
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "example",
description: "An example tool",
inputSchema: {
type: "object",
properties: {
message: {
type: "string",
description: "Message to echo",
},
},
},
},
],
};
});
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch((error) => {
console.error("Server error:", error);
process.exit(1);
});

15
template/tsconfig.json Normal file
View file

@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "Node16",
"moduleResolution": "Node16",
"outDir": "./build",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}