avancement planning
This commit is contained in:
Generated
Vendored
+61
-45
@@ -1,22 +1,44 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const express_1 = __importDefault(require("express"));
|
||||
const mcp_js_1 = require("../../server/mcp.js");
|
||||
const streamableHttp_js_1 = require("../../server/streamableHttp.js");
|
||||
const zod_1 = require("zod");
|
||||
const cors_1 = __importDefault(require("cors"));
|
||||
const z = __importStar(require("zod/v4"));
|
||||
const express_js_1 = require("../../server/express.js");
|
||||
const getServer = () => {
|
||||
// Create an MCP server with implementation details
|
||||
const server = new mcp_js_1.McpServer({
|
||||
name: 'stateless-streamable-http-server',
|
||||
version: '1.0.0',
|
||||
version: '1.0.0'
|
||||
}, { capabilities: { logging: {} } });
|
||||
// Register a simple prompt
|
||||
server.prompt('greeting-template', 'A simple greeting prompt template', {
|
||||
name: zod_1.z.string().describe('Name to include in greeting'),
|
||||
server.registerPrompt('greeting-template', {
|
||||
description: 'A simple greeting prompt template',
|
||||
argsSchema: {
|
||||
name: z.string().describe('Name to include in greeting')
|
||||
}
|
||||
}, async ({ name }) => {
|
||||
return {
|
||||
messages: [
|
||||
@@ -24,32 +46,32 @@ const getServer = () => {
|
||||
role: 'user',
|
||||
content: {
|
||||
type: 'text',
|
||||
text: `Please greet ${name} in a friendly manner.`,
|
||||
},
|
||||
},
|
||||
],
|
||||
text: `Please greet ${name} in a friendly manner.`
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
// Register a tool specifically for testing resumability
|
||||
server.tool('start-notification-stream', 'Starts sending periodic notifications for testing resumability', {
|
||||
interval: zod_1.z.number().describe('Interval in milliseconds between notifications').default(100),
|
||||
count: zod_1.z.number().describe('Number of notifications to send (0 for 100)').default(10),
|
||||
}, async ({ interval, count }, { sendNotification }) => {
|
||||
server.registerTool('start-notification-stream', {
|
||||
description: 'Starts sending periodic notifications for testing resumability',
|
||||
inputSchema: {
|
||||
interval: z.number().describe('Interval in milliseconds between notifications').default(100),
|
||||
count: z.number().describe('Number of notifications to send (0 for 100)').default(10)
|
||||
}
|
||||
}, async ({ interval, count }, extra) => {
|
||||
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
||||
let counter = 0;
|
||||
while (count === 0 || counter < count) {
|
||||
counter++;
|
||||
try {
|
||||
await sendNotification({
|
||||
method: "notifications/message",
|
||||
params: {
|
||||
level: "info",
|
||||
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
|
||||
}
|
||||
});
|
||||
await server.sendLoggingMessage({
|
||||
level: 'info',
|
||||
data: `Periodic notification #${counter} at ${new Date().toISOString()}`
|
||||
}, extra.sessionId);
|
||||
}
|
||||
catch (error) {
|
||||
console.error("Error sending notification:", error);
|
||||
console.error('Error sending notification:', error);
|
||||
}
|
||||
// Wait for the specified interval
|
||||
await sleep(interval);
|
||||
@@ -58,36 +80,30 @@ const getServer = () => {
|
||||
content: [
|
||||
{
|
||||
type: 'text',
|
||||
text: `Started sending periodic notifications every ${interval}ms`,
|
||||
text: `Started sending periodic notifications every ${interval}ms`
|
||||
}
|
||||
],
|
||||
]
|
||||
};
|
||||
});
|
||||
// Create a simple resource at a fixed URI
|
||||
server.resource('greeting-resource', 'https://example.com/greetings/default', { mimeType: 'text/plain' }, async () => {
|
||||
server.registerResource('greeting-resource', 'https://example.com/greetings/default', { mimeType: 'text/plain' }, async () => {
|
||||
return {
|
||||
contents: [
|
||||
{
|
||||
uri: 'https://example.com/greetings/default',
|
||||
text: 'Hello, world!',
|
||||
},
|
||||
],
|
||||
text: 'Hello, world!'
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
return server;
|
||||
};
|
||||
const app = (0, express_1.default)();
|
||||
app.use(express_1.default.json());
|
||||
// Configure CORS to expose Mcp-Session-Id header for browser-based clients
|
||||
app.use((0, cors_1.default)({
|
||||
origin: '*', // Allow all origins - adjust as needed for production
|
||||
exposedHeaders: ['Mcp-Session-Id']
|
||||
}));
|
||||
const app = (0, express_js_1.createMcpExpressApp)();
|
||||
app.post('/mcp', async (req, res) => {
|
||||
const server = getServer();
|
||||
try {
|
||||
const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
||||
sessionIdGenerator: undefined,
|
||||
sessionIdGenerator: undefined
|
||||
});
|
||||
await server.connect(transport);
|
||||
await transport.handleRequest(req, res, req.body);
|
||||
@@ -104,9 +120,9 @@ app.post('/mcp', async (req, res) => {
|
||||
jsonrpc: '2.0',
|
||||
error: {
|
||||
code: -32603,
|
||||
message: 'Internal server error',
|
||||
message: 'Internal server error'
|
||||
},
|
||||
id: null,
|
||||
id: null
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -114,10 +130,10 @@ app.post('/mcp', async (req, res) => {
|
||||
app.get('/mcp', async (req, res) => {
|
||||
console.log('Received GET MCP request');
|
||||
res.writeHead(405).end(JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
jsonrpc: '2.0',
|
||||
error: {
|
||||
code: -32000,
|
||||
message: "Method not allowed."
|
||||
message: 'Method not allowed.'
|
||||
},
|
||||
id: null
|
||||
}));
|
||||
@@ -125,17 +141,17 @@ app.get('/mcp', async (req, res) => {
|
||||
app.delete('/mcp', async (req, res) => {
|
||||
console.log('Received DELETE MCP request');
|
||||
res.writeHead(405).end(JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
jsonrpc: '2.0',
|
||||
error: {
|
||||
code: -32000,
|
||||
message: "Method not allowed."
|
||||
message: 'Method not allowed.'
|
||||
},
|
||||
id: null
|
||||
}));
|
||||
});
|
||||
// Start the server
|
||||
const PORT = 3000;
|
||||
app.listen(PORT, (error) => {
|
||||
app.listen(PORT, error => {
|
||||
if (error) {
|
||||
console.error('Failed to start server:', error);
|
||||
process.exit(1);
|
||||
|
||||
Reference in New Issue
Block a user