MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / createUnifiedMCPServer

Function createUnifiedMCPServer

server/src/mcp/server.ts:161–224  ·  view source on GitHub ↗
(authContext?: MCPAuthContext)

Source from the content-addressed store, hash-verified

159 * - Validation tools: Schema and adagents.json validation
160 */
161export function createUnifiedMCPServer(authContext?: MCPAuthContext): Server {
162 const server = new Server(
163 {
164 name: 'addie',
165 version: '1.0.0',
166 },
167 {
168 capabilities: {
169 resources: {},
170 tools: {},
171 },
172 }
173 );
174
175 const tools = getAllTools();
176 const { handlers, directoryHandler } = getHandlers();
177
178 // List available tools
179 server.setRequestHandler(ListToolsRequestSchema, async () => {
180 logger.debug({ toolCount: tools.all.length }, 'MCP: Listing tools');
181 return { tools: tools.all };
182 });
183
184 // Handle tool calls
185 server.setRequestHandler(CallToolRequestSchema, async (request) => {
186 const { name, arguments: args } = request.params;
187 logger.debug({ tool: name }, 'MCP: Tool call');
188
189 const handler = handlers.get(name);
190 if (!handler) {
191 logger.warn({ tool: name }, 'MCP: Unknown tool');
192 return {
193 content: [{ type: 'text', text: JSON.stringify({ error: `Unknown tool: ${name}` }) }],
194 isError: true,
195 };
196 }
197
198 try {
199 const result = await handler(args as Record<string, unknown> || {}, authContext);
200 return result as {
201 content: Array<{ type: string; text?: string; resource?: { uri: string; mimeType: string; text: string } }>;
202 isError?: boolean;
203 };
204 } catch (error) {
205 logger.error({ error, tool: name }, 'MCP: Tool execution error');
206 return {
207 content: [{ type: 'text', text: JSON.stringify({ error: error instanceof Error ? error.message : 'Unknown error' }) }],
208 isError: true,
209 };
210 }
211 });
212
213 // List available resources (from directory)
214 server.setRequestHandler(ListResourcesRequestSchema, async () => {
215 return { resources: RESOURCE_DEFINITIONS };
216 });
217
218 // Read resource contents (from directory)

Callers 1

configureMCPRoutesFunction · 0.85

Calls 6

getAllToolsFunction · 0.85
getHandlersFunction · 0.85
handlerFunction · 0.85
warnMethod · 0.80
handleResourceReadMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected