/
githubmirror
/
serverless
Обзор
Документация
Войти
/
githubmirror
/
serverless
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/mcp/src/stdio-server.js
51 строка
2 KB
Tomasz Czubocha
chore: integrate v4 packages into main repository
19 дек 2025, 00:28
19 дек 2025, 00:28
8cec971
Код
Авторство
О чём код?
#!/usr/bin/env node import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js' import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js' import { registerTools } from './tools-definition.js' import { wrapServerWithAnalytics } from './utils/analytics-utils.js' /** * Starts the MCP stdio server * @param {Object} options - Server options * @param {Function} options.sendAnalytics - Optional function to send analytics events * @returns {Object} - Server instance and transport */ export async function startStdioServer({ sendAnalytics } = {}) { // Create the MCP server instance. const server = new McpServer({ name: 'serverless', version: '1.0.0', }) // Add analytics tracking for tool executions if sendAnalytics function is provided wrapServerWithAnalytics(server, sendAnalytics) // Register all tools on the server registerTools(server) try { // Set up stdio transport const transport = new StdioServerTransport() console.error('Connecting server to transport...') await server.connect(transport) console.error('MCP stdio server started and connected to transport.') return { server, transport, stop: async () => { try { await transport.close() return true } catch (error) { console.error('Error stopping stdio server:', error) return false } }, } } catch (error) { console.error('Error starting MCP stdio server:', error) throw error } }