Skip to content

Commit b8ce369

Browse files
author
vcart
committed
init repo
0 parents  commit b8ce369

13 files changed

Lines changed: 617 additions & 0 deletions

File tree

.gitignore

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Dependency directories
2+
node_modules/
3+
.pnp/
4+
.pnp.js
5+
6+
# Lock files
7+
# Uncomment the next line if you want to ignore package-lock.json
8+
# package-lock.json
9+
yarn.lock
10+
pnpm-lock.yaml
11+
bun.lock
12+
13+
# Build outputs
14+
build/
15+
dist/
16+
out/
17+
18+
# Logs
19+
logs
20+
*.log
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
lerna-debug.log*
25+
26+
# Environment variables
27+
.env
28+
.env.local
29+
.env.development.local
30+
.env.test.local
31+
.env.production.local
32+
33+
# Editor directories and files
34+
.idea/
35+
.vscode/
36+
*.swp
37+
*.swo
38+
*~
39+
.DS_Store
40+
41+
# Testing
42+
coverage/
43+
.nyc_output/
44+
45+
# Temporary files
46+
.tmp/
47+
.temp/
48+
tmp/
49+
temp/
50+
51+
# npm package files
52+
*.tgz
53+
.npmrc
54+
55+
# Cursor specific
56+
.cursor/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Context Labs, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# @mcpdotdirect/create-mcp-server
2+
3+
![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)
4+
![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178C6)
5+
![MCP](https://img.shields.io/badge/MCP-1.6+-green)
6+
7+
A CLI tool to create a new Model Context Protocol (MCP) server project. This package provides a template for building custom MCP servers that can be used by AI agents to interact with external systems and data sources.
8+
9+
## 📋 Usage
10+
11+
You can create a new MCP server project using npx:
12+
13+
```bash
14+
# Create a new MCP server in the current directory
15+
npx @mcpdotdirect/create-mcp-server
16+
17+
# Or with npm
18+
npm init @mcpdotdirect/create-mcp-server
19+
```
20+
21+
This will create a new MCP server project in the current directory with all the necessary files. You'll need to install the dependencies manually after creation.
22+
23+
## 🔭 What's Included
24+
25+
The template includes:
26+
27+
- Basic server setup with both stdio and HTTP transport options
28+
- Structure for defining MCP tools, resources, and prompts
29+
- TypeScript configuration
30+
- Development scripts and configuration
31+
32+
## ✨ Features
33+
34+
- **Dual Transport Support**: Run your MCP server over stdio or HTTP
35+
- **TypeScript**: Full TypeScript support for type safety
36+
- **MCP SDK**: Built on the official Model Context Protocol SDK
37+
- **Extensible**: Easy to add custom tools, resources, and prompts
38+
39+
## 🚀 Getting Started
40+
41+
After creating your project:
42+
43+
1. Install dependencies using your preferred package manager:
44+
```bash
45+
# Using npm
46+
npm install
47+
48+
# Using yarn
49+
yarn
50+
51+
# Using pnpm
52+
pnpm install
53+
54+
# Using bun
55+
bun install
56+
```
57+
58+
2. Start the server:
59+
```bash
60+
# Start the stdio server
61+
npm start
62+
63+
# Or start the HTTP server
64+
npm run start:http
65+
```
66+
67+
3. For development with auto-reload:
68+
```bash
69+
# Development mode with stdio
70+
npm run dev
71+
72+
# Development mode with HTTP
73+
npm run dev:http
74+
```
75+
76+
> **Note**: The default scripts in package.json use Bun as the runtime (e.g., `bun run src/index.ts`). If you prefer to use a different package manager or runtime, you can modify these scripts in your package.json file to use Node.js or another runtime of your choice.
77+
78+
## 🛠️ Adding Custom Tools and Resources
79+
80+
When adding custom tools, resources, or prompts to your MCP server:
81+
82+
1. Use underscores (`_`) instead of hyphens (`-`) in all resource, tool, and prompt names
83+
```typescript
84+
// Good: Uses underscores
85+
server.tool(
86+
"my_custom_tool",
87+
"Description of my custom tool",
88+
{
89+
param_name: z.string().describe("Parameter description")
90+
},
91+
async (params) => {
92+
// Tool implementation
93+
}
94+
);
95+
96+
// Bad: Uses hyphens, may cause issues with Cursor
97+
server.tool(
98+
"my-custom-tool",
99+
"Description of my custom tool",
100+
{
101+
param-name: z.string().describe("Parameter description")
102+
},
103+
async (params) => {
104+
// Tool implementation
105+
}
106+
);
107+
```
108+
109+
2. This naming convention ensures compatibility with Cursor and other AI tools that interact with your MCP server
110+
111+
## 📚 Documentation
112+
113+
For more information about the Model Context Protocol, visit the [MCP Documentation](https://modelcontextprotocol.io/introduction).
114+
115+
## 📄 License
116+
117+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "mcp-server",
3+
"module": "src/index.ts",
4+
"type": "module",
5+
"version": "1.0.0",
6+
"description": "Model Context Protocol (MCP) Server",
7+
"private": true,
8+
"scripts": {
9+
"start": "bun run src/index.ts",
10+
"build": "bun build src/index.ts --outdir build --target node",
11+
"build:http": "bun build src/server/http-server.ts --outdir build --target node",
12+
"dev": "bun --watch src/index.ts",
13+
"start:http": "bun run src/server/http-server.ts",
14+
"dev:http": "bun --watch src/server/http-server.ts"
15+
},
16+
"devDependencies": {
17+
"@types/bun": "latest",
18+
"@types/cors": "^2.8.17",
19+
"@types/express": "^5.0.0",
20+
"@types/node": "^20.11.0"
21+
},
22+
"peerDependencies": {
23+
"typescript": "^5.8.2"
24+
},
25+
"dependencies": {
26+
"@modelcontextprotocol/sdk": "^1.6.1",
27+
"cors": "^2.8.5",
28+
"express": "^4.21.2",
29+
"zod": "^3.24.2"
30+
}
31+
}

src/core/prompts.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2+
import { z } from "zod";
3+
4+
/**
5+
* Register all prompts with the MCP server
6+
* @param server The MCP server instance
7+
*/
8+
export function registerPrompts(server: McpServer) {
9+
// Example prompt
10+
server.prompt(
11+
"greeting",
12+
"A simple greeting prompt",
13+
{
14+
name: z.string().describe("Name to greet")
15+
},
16+
(params: { name: string }) => ({
17+
messages: [{
18+
role: "user",
19+
content: {
20+
type: "text",
21+
text: `Hello, ${params.name}! How can I help you today?`
22+
}
23+
}]
24+
})
25+
);
26+
}

src/core/resources.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2+
import * as services from "./services/index.js";
3+
4+
/**
5+
* Register all resources with the MCP server
6+
* @param server The MCP server instance
7+
*/
8+
export function registerResources(server: McpServer) {
9+
// Example resource
10+
server.resource(
11+
"example_resource",
12+
"example://{id}",
13+
async (uri: URL) => {
14+
const id = uri.pathname.split('/').pop();
15+
return {
16+
contents: [{
17+
uri: uri.toString(),
18+
text: `This is an example resource with ID: ${id}`
19+
}]
20+
};
21+
}
22+
);
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* A simple service for generating greetings
3+
*/
4+
export class GreetingService {
5+
/**
6+
* Generate a greeting message
7+
* @param name The name to greet
8+
* @returns A greeting message
9+
*/
10+
public static generateGreeting(name: string): string {
11+
return `Hello, ${name}! Welcome to the MCP Server.`;
12+
}
13+
14+
/**
15+
* Generate a farewell message
16+
* @param name The name to bid farewell to
17+
* @returns A farewell message
18+
*/
19+
public static generateFarewell(name: string): string {
20+
return `Goodbye, ${name}! Thank you for using the MCP Server.`;
21+
}
22+
}

src/core/services/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Export all services
2+
export * from './greeting-service.js';

src/core/tools.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2+
import { z } from "zod";
3+
import * as services from "./services/index.js";
4+
5+
/**
6+
* Register all tools with the MCP server
7+
*
8+
* @param server The MCP server instance
9+
*/
10+
export function registerTools(server: McpServer) {
11+
// Greeting tool
12+
server.tool(
13+
"hello_world",
14+
"A simple hello world tool",
15+
{
16+
name: z.string().describe("Name to greet")
17+
},
18+
async (params: { name: string }) => {
19+
const greeting = services.GreetingService.generateGreeting(params.name);
20+
return {
21+
content: [
22+
{
23+
type: "text",
24+
text: greeting
25+
}
26+
]
27+
};
28+
}
29+
);
30+
31+
// Farewell tool
32+
server.tool(
33+
"goodbye",
34+
"A simple goodbye tool",
35+
{
36+
name: z.string().describe("Name to bid farewell to")
37+
},
38+
async (params: { name: string }) => {
39+
const farewell = services.GreetingService.generateFarewell(params.name);
40+
return {
41+
content: [
42+
{
43+
type: "text",
44+
text: farewell
45+
}
46+
]
47+
};
48+
}
49+
);
50+
}

src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2+
import startServer from "./server/server.js";
3+
4+
// Start the server
5+
async function main() {
6+
try {
7+
const server = await startServer();
8+
const transport = new StdioServerTransport();
9+
await server.connect(transport);
10+
console.error("MCP Server running on stdio");
11+
} catch (error) {
12+
console.error("Error starting MCP server:", error);
13+
process.exit(1);
14+
}
15+
}
16+
17+
main().catch((error) => {
18+
console.error("Fatal error in main():", error);
19+
process.exit(1);
20+
});

0 commit comments

Comments
 (0)