MCPcopy
hub / github.com/serverless/serverless / startStdioServer

Function startStdioServer

packages/mcp/src/stdio-server.js:14–51  ·  view source on GitHub ↗
({ sendAnalytics } = {})

Source from the content-addressed store, hash-verified

12 * @returns {Object} - Server instance and transport
13 */
14export async function startStdioServer({ sendAnalytics } = {}) {
15 // Create the MCP server instance.
16 const server = new McpServer({
17 name: 'serverless',
18 version: '1.0.0',
19 })
20
21 // Add analytics tracking for tool executions if sendAnalytics function is provided
22 wrapServerWithAnalytics(server, sendAnalytics)
23
24 // Register all tools on the server
25 registerTools(server)
26
27 try {
28 // Set up stdio transport
29 const transport = new StdioServerTransport()
30 console.error('Connecting server to transport...')
31 await server.connect(transport)
32 console.error('MCP stdio server started and connected to transport.')
33
34 return {
35 server,
36 transport,
37 stop: async () => {
38 try {
39 await transport.close()
40 return true
41 } catch (error) {
42 console.error('Error stopping stdio server:', error)
43 return false
44 }
45 },
46 }
47 } catch (error) {
48 console.error('Error starting MCP stdio server:', error)
49 throw error
50 }
51}

Callers 1

commandMcpFunction · 0.90

Calls 4

wrapServerWithAnalyticsFunction · 0.90
registerToolsFunction · 0.90
errorMethod · 0.80
connectMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…