11import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
2- import { getAgentStatus } from "mcp/getAgentStatus "
3- import { runStandaloneAgentLoop } from "mcp/runStandaloneAgentLoop "
4- import { z } from "zod "
2+ import { registerAskAgentTool } from "mcp/tools/askAgent "
3+ import { registerAskAgentSlackbotTool } from "mcp/tools/askAgentSlackbot "
4+ import { registerGetAgentStatusTool } from "mcp/tools/getAgentStatus "
55
66export const getMcpServer = ( ) => {
77 // Store Claude Agent SDK sessionId per-instance (not shared across threads)
@@ -25,127 +25,29 @@ export const getMcpServer = () => {
2525 }
2626 )
2727
28- mcpServer . registerTool (
29- "ask_agent" ,
30- {
31- description :
32- "Passes a query to the internal agent and returns its full output. The agent has access to configured MCP tools and will provide a complete response. DO NOT reprocess, analyze, or summarize the output - return it directly to the user as-is." ,
33- inputSchema : {
34- query : z . string ( ) . min ( 1 ) . describe ( "The query to send to the agent" ) ,
28+ // Register tools
29+ registerAskAgentTool ( {
30+ mcpServer,
31+ context : {
32+ get sessionId ( ) {
33+ return sessionId
3534 } ,
36- } ,
37- async ( { query } ) => {
38- const existingConnectedServers = sessionId
39- ? sessionConnectedServers . get ( sessionId )
40- : undefined
41-
42- const { response, connectedServers } = await runStandaloneAgentLoop ( {
43- prompt : query ,
44- mcpServer,
45- sessionId,
46- existingConnectedServers,
47- onSessionIdReceived : ( newSessionId ) => {
48- sessionId = newSessionId
49- } ,
50- } )
51-
52- // Update the session's connected servers
53- if ( sessionId ) {
54- sessionConnectedServers . set ( sessionId , connectedServers )
55- }
56-
57- return {
58- content : [
59- {
60- type : "text" ,
61- text : response ,
62- } ,
63- ] ,
64- }
65- }
66- )
67-
68- mcpServer . registerTool (
69- "ask_agent_slackbot" ,
70- {
71- description :
72- "Slack bot integration tool. Passes a query to the internal agent and returns a response optimized for Slack. Supports per-thread session isolation." ,
73- inputSchema : {
74- query : z
75- . string ( )
76- . min ( 1 )
77- . describe ( "The slack query to send to the agent" ) ,
78- systemPrompt : z
79- . string ( )
80- . optional ( )
81- . describe ( "Optional additional system prompt to prepend" ) ,
82- threadId : z
83- . string ( )
84- . optional ( )
85- . describe ( "Slack thread identifier for session isolation" ) ,
35+ sessionConnectedServers,
36+ onSessionIdUpdate : ( newSessionId ) => {
37+ sessionId = newSessionId
8638 } ,
8739 } ,
88- async ( { query, systemPrompt, threadId } ) => {
89- const existingSessionId = threadId
90- ? threadSessions . get ( threadId )
91- : undefined
40+ } )
9241
93- const existingConnectedServers = existingSessionId
94- ? sessionConnectedServers . get ( existingSessionId )
95- : undefined
96-
97- const { response, connectedServers } = await runStandaloneAgentLoop ( {
98- prompt : query ,
99- mcpServer,
100- sessionId : existingSessionId ,
101- additionalSystemPrompt : systemPrompt ,
102- existingConnectedServers,
103- onSessionIdReceived : ( newSessionId ) => {
104- if ( threadId ) {
105- threadSessions . set ( threadId , newSessionId )
106- }
107- } ,
108- } )
109-
110- // Update the session's connected servers
111- if ( existingSessionId || threadId ) {
112- const sessionId = existingSessionId || threadSessions . get ( threadId ! )
113- if ( sessionId ) {
114- sessionConnectedServers . set ( sessionId , connectedServers )
115- }
116- }
117-
118- return {
119- content : [
120- {
121- type : "text" ,
122- text : response ,
123- } ,
124- ] ,
125- }
126- }
127- )
128-
129- mcpServer . registerTool (
130- "get_agent_status" ,
131- {
132- description :
133- "Get the status of the agent including which MCP servers it has access to. Call this on initialization to see available servers." ,
134- inputSchema : { } ,
42+ registerAskAgentSlackbotTool ( {
43+ mcpServer,
44+ context : {
45+ threadSessions,
46+ sessionConnectedServers,
13547 } ,
136- async ( ) => {
137- const status = await getAgentStatus ( mcpServer )
48+ } )
13849
139- return {
140- content : [
141- {
142- type : "text" ,
143- text : JSON . stringify ( status , null , 2 ) ,
144- } ,
145- ] ,
146- }
147- }
148- )
50+ registerGetAgentStatusTool ( { mcpServer } )
14951
15052 return mcpServer
15153}
0 commit comments