Skip to content

Commit fa43fa8

Browse files
committed
feat: add build before start. this one is for you, vibe coders ;)
1 parent 33b1776 commit fa43fa8

File tree

4 files changed

+50
-52
lines changed

4 files changed

+50
-52
lines changed

README.md

+13-46
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,17 @@ The framework provides a powerful CLI for managing your MCP server projects:
4646
```bash
4747
# Create a new project
4848
mcp create <your project name here>
49+
50+
# Create a new project with the new EXPERIMENTAL HTTP transport
51+
Heads up: This will set cors allowed origin to "*", modify it in the index if you wish
52+
mcp create <your project name here> --http --port 3000 --cors
4953
```
5054
55+
# Options:
56+
# --http: Use HTTP transport instead of default stdio
57+
# --port <number>: Specify HTTP port (default: 8080)
58+
# --cors: Enable CORS with wildcard (*) access
59+
5160
### Adding a Tool
5261
5362
```bash
@@ -250,47 +259,9 @@ const server = new MCPServer({
250259
});
251260
```
252261
253-
#### CORS Configuration
254-
255-
The SSE transport supports flexible CORS configuration. By default, it uses permissive settings suitable for development. For production, you should configure CORS according to your security requirements:
256-
257-
```typescript
258-
const server = new MCPServer({
259-
transport: {
260-
type: "sse",
261-
options: {
262-
// Restrict to specific origin
263-
cors: {
264-
allowOrigin: "https://myapp.com",
265-
allowMethods: "GET, POST",
266-
allowHeaders: "Content-Type, Authorization",
267-
exposeHeaders: "Content-Type, Authorization",
268-
maxAge: "3600"
269-
}
270-
}
271-
}
272-
});
273-
274-
// Or with multiple allowed origins
275-
const server = new MCPServer({
276-
transport: {
277-
type: "sse",
278-
options: {
279-
cors: {
280-
allowOrigin: "https://app1.com, https://app2.com",
281-
allowMethods: "GET, POST, OPTIONS",
282-
allowHeaders: "Content-Type, Authorization, Custom-Header",
283-
exposeHeaders: "Content-Type, Authorization",
284-
maxAge: "86400"
285-
}
286-
}
287-
}
288-
});
289-
```
290-
291-
### HTTP Stream Transport (New!)
262+
### HTTP Stream Transport
292263
293-
The HTTP Stream transport provides a streamable JSON-RPC interface over HTTP with support for batch and streaming response modes:
264+
To use HTTP Stream transport:
294265
295266
```typescript
296267
const server = new MCPServer({
@@ -316,13 +287,9 @@ const server = new MCPServer({
316287
historyDuration: 300000, // Optional (default: 300000ms = 5min) - how long to keep message history
317288
},
318289
319-
// CORS configuration (same as SSE transport)
290+
// CORS configuration
320291
cors: {
321-
allowOrigin: "*",
322-
allowMethods: "GET, POST, DELETE, OPTIONS",
323-
allowHeaders: "Content-Type, Accept, Authorization, x-api-key, Mcp-Session-Id, Last-Event-ID",
324-
exposeHeaders: "Content-Type, Authorization, x-api-key, Mcp-Session-Id",
325-
maxAge: "86400"
292+
allowOrigin: "*" // Other CORS options use defaults
326293
}
327294
}
328295
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "mcp-framework",
3-
"version": "0.2.1",
3+
"version": "0.2.2-beta.1",
4+
45
"description": "Framework for building Model Context Protocol (MCP) servers in Typescript",
56
"type": "module",
67
"author": "Alex Andru <[email protected]>",

src/cli/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const program = new Command();
1111
program
1212
.name("mcp")
1313
.description("CLI for managing MCP server projects")
14-
.version("0.2.0");
14+
.version("0.2.2");
1515

1616
program
1717
.command("build")
@@ -22,6 +22,9 @@ program
2222
.command("create")
2323
.description("Create a new MCP server project")
2424
.argument("[name]", "project name")
25+
.option("--http", "use HTTP transport instead of default stdio")
26+
.option("--cors", "enable CORS with wildcard (*) access")
27+
.option("--port <number>", "specify HTTP port (only valid with --http)", (val) => parseInt(val, 10))
2528
.action(createProject);
2629

2730
program

src/cli/project/create.ts

+31-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import prompts from "prompts";
55
import { generateReadme } from "../templates/readme.js";
66
import { execa } from "execa";
77

8-
export async function createProject(name?: string) {
8+
export async function createProject(name?: string, options?: { http?: boolean, cors?: boolean, port?: number }) {
99
let projectName: string;
1010

1111
if (!name) {
@@ -57,7 +57,7 @@ export async function createProject(name?: string) {
5757
scripts: {
5858
build: "tsc && mcp-build",
5959
watch: "tsc --watch",
60-
start: "node dist/index.js"
60+
start: "npm run build && node dist/index.js"
6161
},
6262
dependencies: {
6363
"mcp-framework": "^0.2.1"
@@ -84,11 +84,38 @@ export async function createProject(name?: string) {
8484
exclude: ["node_modules"],
8585
};
8686

87-
const indexTs = `import { MCPServer } from "mcp-framework";
87+
let indexTs = "";
88+
89+
if (options?.http) {
90+
const port = options.port || 8080;
91+
let transportConfig = `\n transport: {
92+
type: "http-stream",
93+
options: {
94+
port: ${port}`;
95+
96+
if (options.cors) {
97+
transportConfig += `,
98+
cors: {
99+
allowOrigin: "*"
100+
}`;
101+
}
102+
103+
transportConfig += `
104+
}
105+
}`;
106+
107+
indexTs = `import { MCPServer } from "mcp-framework";
108+
109+
const server = new MCPServer({${transportConfig}});
110+
111+
server.start();`;
112+
} else {
113+
indexTs = `import { MCPServer } from "mcp-framework";
88114
89115
const server = new MCPServer();
90116
91117
server.start();`;
118+
}
92119

93120
const exampleToolTs = `import { MCPTool } from "mcp-framework";
94121
import { z } from "zod";
@@ -175,7 +202,7 @@ Project ${projectName} created and built successfully!
175202
You can now:
176203
1. cd ${projectName}
177204
2. Add more tools using:
178-
mcp add tool <name>
205+
mcp add tool <n>
179206
`);
180207
} catch (error) {
181208
console.error("Error creating project:", error);

0 commit comments

Comments
 (0)