/ src / index.ts
index.ts
  1  #!/usr/bin/env node
  2  /**
  3   * AURYN - InterBrain MCP Server
  4   *
  5   * Exposes the DreamNode system to AI agents and external tools via MCP.
  6   */
  7  
  8  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
  9  import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
 10  import {
 11    CallToolRequestSchema,
 12    ListToolsRequestSchema,
 13  } from '@modelcontextprotocol/sdk/types.js';
 14  
 15  import { foundationTools } from './tools/foundation.js';
 16  import { submoduleTools } from './tools/submodule.js';
 17  import { semanticTools } from './tools/semantic.js';
 18  import { agentLoaderTools } from './tools/agent-loader.js';
 19  import { spawnChatTools } from './tools/spawn-chat.js';
 20  import { dreamweavingTools } from './tools/dreamweaving.js';
 21  import { popOutTools } from './tools/pop-out.js';
 22  import { liminalWebTools } from './tools/liminal-web.js';
 23  import { mergeTools } from './tools/merge.js';
 24  import { socialResonanceTools } from './tools/social-resonance.js';
 25  import { cherryPickTools } from './tools/cherry-pick.js';
 26  import { coherenceBeaconTools } from './tools/coherence-beacon.js';
 27  
 28  // Combine all tools
 29  const allTools = {
 30    ...foundationTools,
 31    ...submoduleTools,
 32    ...semanticTools,
 33    ...agentLoaderTools,
 34    ...spawnChatTools,
 35    ...dreamweavingTools,
 36    ...popOutTools,
 37    ...liminalWebTools,
 38    ...mergeTools,
 39    ...socialResonanceTools,
 40    ...cherryPickTools,
 41    ...coherenceBeaconTools,
 42  };
 43  
 44  // Create MCP server
 45  const server = new Server(
 46    {
 47      name: 'auryn',
 48      version: '0.1.0',
 49    },
 50    {
 51      capabilities: {
 52        tools: {},
 53      },
 54    }
 55  );
 56  
 57  // Handle tool listing
 58  server.setRequestHandler(ListToolsRequestSchema, async () => {
 59    return {
 60      tools: Object.values(allTools).map(tool => ({
 61        name: tool.name,
 62        description: tool.description,
 63        inputSchema: tool.inputSchema
 64      }))
 65    };
 66  });
 67  
 68  // Handle tool execution
 69  server.setRequestHandler(CallToolRequestSchema, async (request) => {
 70    const { name, arguments: args } = request.params;
 71  
 72    const tool = allTools[name as keyof typeof allTools];
 73    if (!tool) {
 74      return {
 75        content: [
 76          {
 77            type: 'text',
 78            text: JSON.stringify({ error: `Unknown tool: ${name}` })
 79          }
 80        ],
 81        isError: true
 82      };
 83    }
 84  
 85    try {
 86      // eslint-disable-next-line @typescript-eslint/no-explicit-any
 87      const result = await (tool.handler as any)(args || {});
 88      return {
 89        content: [
 90          {
 91            type: 'text',
 92            text: JSON.stringify(result, null, 2)
 93          }
 94        ]
 95      };
 96    } catch (error) {
 97      const errorMessage = error instanceof Error ? error.message : 'Unknown error';
 98      return {
 99        content: [
100          {
101            type: 'text',
102            text: JSON.stringify({ error: errorMessage })
103          }
104        ],
105        isError: true
106      };
107    }
108  });
109  
110  // Start server
111  async function main() {
112    console.error('AURYN MCP Server starting...');
113    console.error('Available tools:', Object.keys(allTools).join(', '));
114  
115    const transport = new StdioServerTransport();
116    await server.connect(transport);
117  
118    console.error('AURYN MCP Server running on stdio');
119  }
120  
121  main().catch((error) => {
122    console.error('Fatal error:', error);
123    process.exit(1);
124  });