Skip to main content
Glama
server.ts2.86 kB
/** * Yuque MCP Server - Main Server Implementation * 语雀MCP服务器 - 主服务器实现 */ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { CallToolRequestSchema, ListToolsRequestSchema, McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; import { YuqueClient } from './yuque-client.js'; import { config } from './config/index.js'; import { YUQUE_TOOLS } from './tools/definitions.js'; import { handleTool } from './tools/handlers.js'; export interface ServerOptions { name?: string; version?: string; } /** * Create and configure the Yuque MCP Server */ export async function createServer(options: ServerOptions = {}): Promise<Server> { const serverConfig = config.get(); const server = new Server( { name: options.name || 'yuque-mcp-server', version: options.version || '1.1.0', }, { capabilities: { tools: {}, }, } ); const yuqueClient = new YuqueClient(serverConfig); // Handle tool listing requests server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: YUQUE_TOOLS, }; }); // Handle tool execution requests server.setRequestHandler(CallToolRequestSchema, async (request) => { try { return await handleTool(request, { client: yuqueClient }); } catch (error) { if (error instanceof McpError) { throw error; } const errorMessage = error instanceof Error ? error.message : String(error); throw new McpError( ErrorCode.InternalError, `Error executing tool: ${errorMessage}` ); } }); return server; } /** * Start the MCP server with stdio transport */ export async function startServer(options: ServerOptions = {}): Promise<void> { console.error('📡 Initializing Yuque MCP Server...'); try { const validation = config.validate(); if (!validation.isValid) { console.error(`❌ Configuration error: ${validation.error}`); process.exit(1); } console.error('🔧 Loading Yuque API client...'); const server = await createServer(options); const transport = new StdioServerTransport(); console.error('🔗 Establishing MCP connection...'); await server.connect(transport); console.error(''); console.error('✅ Yuque MCP Server is now running!'); console.error('🎯 Connected via stdio transport'); console.error('📚 Available tools: 9 Yuque operations'); console.error('🔍 Ready to assist with Yuque content management'); console.error(''); } catch (error) { console.error(''); console.error('💥 Failed to start server:', error); console.error(' Please check your network connection and API token'); process.exit(1); } }

Implementation Reference

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tanis2010/yuque-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server