agent-orchestrator-mcp-server 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,55 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { z } from 'zod';
3
+ import type { IAgentOrchestratorClient } from '../orchestrator-client/orchestrator-client.js';
4
+ export declare const ActionSessionSchema: z.ZodObject<{
5
+ session_id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
6
+ action: z.ZodEnum<["follow_up", "pause", "restart", "archive", "unarchive"]>;
7
+ prompt: z.ZodOptional<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ session_id: string | number;
10
+ action: "follow_up" | "pause" | "restart" | "archive" | "unarchive";
11
+ prompt?: string | undefined;
12
+ }, {
13
+ session_id: string | number;
14
+ action: "follow_up" | "pause" | "restart" | "archive" | "unarchive";
15
+ prompt?: string | undefined;
16
+ }>;
17
+ export declare function actionSessionTool(_server: Server, clientFactory: () => IAgentOrchestratorClient): {
18
+ name: string;
19
+ description: string;
20
+ inputSchema: {
21
+ type: "object";
22
+ properties: {
23
+ session_id: {
24
+ oneOf: {
25
+ type: string;
26
+ }[];
27
+ description: "Session ID (numeric) or slug (string) to perform the action on.";
28
+ };
29
+ action: {
30
+ type: string;
31
+ enum: readonly ["follow_up", "pause", "restart", "archive", "unarchive"];
32
+ description: "Action to perform: \"follow_up\" (send prompt to paused session), \"pause\" (pause running session), \"restart\" (restart paused/failed session), \"archive\" (archive session), \"unarchive\" (restore archived session)";
33
+ };
34
+ prompt: {
35
+ type: string;
36
+ description: "Required for \"follow_up\" action. The prompt to send to the agent. Not used for other actions.";
37
+ };
38
+ };
39
+ required: string[];
40
+ };
41
+ handler: (args: unknown) => Promise<{
42
+ content: {
43
+ type: string;
44
+ text: string;
45
+ }[];
46
+ isError: boolean;
47
+ } | {
48
+ content: {
49
+ type: string;
50
+ text: string;
51
+ }[];
52
+ isError?: undefined;
53
+ }>;
54
+ };
55
+ //# sourceMappingURL=action-session.d.ts.map
@@ -0,0 +1,182 @@
1
+ import { z } from 'zod';
2
+ const PARAM_DESCRIPTIONS = {
3
+ session_id: 'Session ID (numeric) or slug (string) to perform the action on.',
4
+ action: 'Action to perform: "follow_up" (send prompt to paused session), "pause" (pause running session), "restart" (restart paused/failed session), "archive" (archive session), "unarchive" (restore archived session)',
5
+ prompt: 'Required for "follow_up" action. The prompt to send to the agent. Not used for other actions.',
6
+ };
7
+ const ACTION_ENUM = ['follow_up', 'pause', 'restart', 'archive', 'unarchive'];
8
+ export const ActionSessionSchema = z.object({
9
+ session_id: z.union([z.string(), z.number()]).describe(PARAM_DESCRIPTIONS.session_id),
10
+ action: z.enum(ACTION_ENUM).describe(PARAM_DESCRIPTIONS.action),
11
+ prompt: z.string().optional().describe(PARAM_DESCRIPTIONS.prompt),
12
+ });
13
+ const TOOL_DESCRIPTION = `Perform an action on an agent session.
14
+
15
+ **Actions:**
16
+ - **follow_up**: Send a follow-up prompt to a paused session (requires "prompt" parameter)
17
+ - **pause**: Pause a running session, transitioning it to "needs_input" status
18
+ - **restart**: Restart a paused or failed session without providing new input
19
+ - **archive**: Archive a session (marks as completed)
20
+ - **unarchive**: Restore an archived session to "needs_input" status
21
+
22
+ **Status requirements:**
23
+ - follow_up: Session must be "needs_input"
24
+ - pause: Session must be "running"
25
+ - restart: Session must be "needs_input" or "failed"
26
+ - archive: Session can be in any status except "archived"
27
+ - unarchive: Session must be "archived"
28
+
29
+ **Use cases:**
30
+ - Provide additional instructions to an agent
31
+ - Control session lifecycle (pause, restart)
32
+ - Organize sessions (archive, unarchive)`;
33
+ export function actionSessionTool(_server, clientFactory) {
34
+ return {
35
+ name: 'action_session',
36
+ description: TOOL_DESCRIPTION,
37
+ inputSchema: {
38
+ type: 'object',
39
+ properties: {
40
+ session_id: {
41
+ oneOf: [{ type: 'string' }, { type: 'number' }],
42
+ description: PARAM_DESCRIPTIONS.session_id,
43
+ },
44
+ action: {
45
+ type: 'string',
46
+ enum: ACTION_ENUM,
47
+ description: PARAM_DESCRIPTIONS.action,
48
+ },
49
+ prompt: {
50
+ type: 'string',
51
+ description: PARAM_DESCRIPTIONS.prompt,
52
+ },
53
+ },
54
+ required: ['session_id', 'action'],
55
+ },
56
+ handler: async (args) => {
57
+ try {
58
+ const validatedArgs = ActionSessionSchema.parse(args);
59
+ const client = clientFactory();
60
+ const { session_id, action, prompt } = validatedArgs;
61
+ // Validate that prompt is provided for follow_up action
62
+ if (action === 'follow_up' && !prompt) {
63
+ return {
64
+ content: [
65
+ {
66
+ type: 'text',
67
+ text: 'Error: The "prompt" parameter is required for the "follow_up" action.',
68
+ },
69
+ ],
70
+ isError: true,
71
+ };
72
+ }
73
+ let result;
74
+ switch (action) {
75
+ case 'follow_up': {
76
+ const response = await client.followUp(session_id, prompt);
77
+ const lines = [
78
+ `## Follow-up Sent`,
79
+ '',
80
+ `- **Session ID:** ${response.session.id}`,
81
+ `- **Title:** ${response.session.title}`,
82
+ `- **New Status:** ${response.session.status}`,
83
+ ];
84
+ if (response.message) {
85
+ lines.push(`- **Message:** ${response.message}`);
86
+ }
87
+ if (response.session.running_job_id) {
88
+ lines.push(`- **Job ID:** ${response.session.running_job_id}`);
89
+ }
90
+ result = lines.join('\n');
91
+ break;
92
+ }
93
+ case 'pause': {
94
+ const response = await client.pauseSession(session_id);
95
+ const lines = [
96
+ `## Session Paused`,
97
+ '',
98
+ `- **Session ID:** ${response.session.id}`,
99
+ `- **Title:** ${response.session.title}`,
100
+ `- **New Status:** ${response.session.status}`,
101
+ ];
102
+ if (response.message) {
103
+ lines.push(`- **Message:** ${response.message}`);
104
+ }
105
+ result = lines.join('\n');
106
+ break;
107
+ }
108
+ case 'restart': {
109
+ const response = await client.restartSession(session_id);
110
+ const lines = [
111
+ `## Session Restarted`,
112
+ '',
113
+ `- **Session ID:** ${response.session.id}`,
114
+ `- **Title:** ${response.session.title}`,
115
+ `- **New Status:** ${response.session.status}`,
116
+ ];
117
+ if (response.message) {
118
+ lines.push(`- **Message:** ${response.message}`);
119
+ }
120
+ if (response.session.running_job_id) {
121
+ lines.push(`- **Job ID:** ${response.session.running_job_id}`);
122
+ }
123
+ result = lines.join('\n');
124
+ break;
125
+ }
126
+ case 'archive': {
127
+ const session = await client.archiveSession(session_id);
128
+ const lines = [
129
+ `## Session Archived`,
130
+ '',
131
+ `- **Session ID:** ${session.id}`,
132
+ `- **Title:** ${session.title}`,
133
+ `- **New Status:** ${session.status}`,
134
+ `- **Archived At:** ${session.archived_at}`,
135
+ ];
136
+ result = lines.join('\n');
137
+ break;
138
+ }
139
+ case 'unarchive': {
140
+ const session = await client.unarchiveSession(session_id);
141
+ const lines = [
142
+ `## Session Unarchived`,
143
+ '',
144
+ `- **Session ID:** ${session.id}`,
145
+ `- **Title:** ${session.title}`,
146
+ `- **New Status:** ${session.status}`,
147
+ ];
148
+ result = lines.join('\n');
149
+ break;
150
+ }
151
+ default: {
152
+ // This should never happen due to Zod validation
153
+ const _exhaustiveCheck = action;
154
+ return {
155
+ content: [
156
+ {
157
+ type: 'text',
158
+ text: `Error: Unknown action "${_exhaustiveCheck}"`,
159
+ },
160
+ ],
161
+ isError: true,
162
+ };
163
+ }
164
+ }
165
+ return {
166
+ content: [{ type: 'text', text: result }],
167
+ };
168
+ }
169
+ catch (error) {
170
+ return {
171
+ content: [
172
+ {
173
+ type: 'text',
174
+ text: `Error performing action: ${error instanceof Error ? error.message : 'Unknown error'}`,
175
+ },
176
+ ],
177
+ isError: true,
178
+ };
179
+ }
180
+ },
181
+ };
182
+ }
@@ -0,0 +1,95 @@
1
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
+ import { z } from 'zod';
3
+ import type { IAgentOrchestratorClient } from '../orchestrator-client/orchestrator-client.js';
4
+ export declare const GetSessionSchema: z.ZodObject<{
5
+ id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
6
+ include_transcript: z.ZodOptional<z.ZodBoolean>;
7
+ include_logs: z.ZodOptional<z.ZodBoolean>;
8
+ logs_page: z.ZodOptional<z.ZodNumber>;
9
+ logs_per_page: z.ZodOptional<z.ZodNumber>;
10
+ include_subagent_transcripts: z.ZodOptional<z.ZodBoolean>;
11
+ transcripts_page: z.ZodOptional<z.ZodNumber>;
12
+ transcripts_per_page: z.ZodOptional<z.ZodNumber>;
13
+ }, "strip", z.ZodTypeAny, {
14
+ id: string | number;
15
+ include_transcript?: boolean | undefined;
16
+ include_logs?: boolean | undefined;
17
+ logs_page?: number | undefined;
18
+ logs_per_page?: number | undefined;
19
+ include_subagent_transcripts?: boolean | undefined;
20
+ transcripts_page?: number | undefined;
21
+ transcripts_per_page?: number | undefined;
22
+ }, {
23
+ id: string | number;
24
+ include_transcript?: boolean | undefined;
25
+ include_logs?: boolean | undefined;
26
+ logs_page?: number | undefined;
27
+ logs_per_page?: number | undefined;
28
+ include_subagent_transcripts?: boolean | undefined;
29
+ transcripts_page?: number | undefined;
30
+ transcripts_per_page?: number | undefined;
31
+ }>;
32
+ export declare function getSessionTool(_server: Server, clientFactory: () => IAgentOrchestratorClient): {
33
+ name: string;
34
+ description: string;
35
+ inputSchema: {
36
+ type: "object";
37
+ properties: {
38
+ id: {
39
+ oneOf: {
40
+ type: string;
41
+ }[];
42
+ description: "Session ID (numeric) or slug (string). Examples: \"1\", \"fix-auth-bug-20250115\"";
43
+ };
44
+ include_transcript: {
45
+ type: string;
46
+ description: "Include the full transcript of the session. Default: false. Set to true for complete conversation history.";
47
+ };
48
+ include_logs: {
49
+ type: string;
50
+ description: "Include logs for the session. Default: false. Use logs_page and logs_per_page for pagination.";
51
+ };
52
+ logs_page: {
53
+ type: string;
54
+ minimum: number;
55
+ description: "Page number for logs pagination. Default: 1";
56
+ };
57
+ logs_per_page: {
58
+ type: string;
59
+ minimum: number;
60
+ maximum: number;
61
+ description: "Number of logs per page (1-100). Default: 25";
62
+ };
63
+ include_subagent_transcripts: {
64
+ type: string;
65
+ description: "Include subagent transcripts for the session. Default: false. Use transcripts_page and transcripts_per_page for pagination.";
66
+ };
67
+ transcripts_page: {
68
+ type: string;
69
+ minimum: number;
70
+ description: "Page number for subagent transcripts pagination. Default: 1";
71
+ };
72
+ transcripts_per_page: {
73
+ type: string;
74
+ minimum: number;
75
+ maximum: number;
76
+ description: "Number of subagent transcripts per page (1-100). Default: 25";
77
+ };
78
+ };
79
+ required: string[];
80
+ };
81
+ handler: (args: unknown) => Promise<{
82
+ content: {
83
+ type: string;
84
+ text: string;
85
+ }[];
86
+ isError?: undefined;
87
+ } | {
88
+ content: {
89
+ type: string;
90
+ text: string;
91
+ }[];
92
+ isError: boolean;
93
+ }>;
94
+ };
95
+ //# sourceMappingURL=get-session.d.ts.map
@@ -0,0 +1,271 @@
1
+ import { z } from 'zod';
2
+ const PARAM_DESCRIPTIONS = {
3
+ id: 'Session ID (numeric) or slug (string). Examples: "1", "fix-auth-bug-20250115"',
4
+ include_transcript: 'Include the full transcript of the session. Default: false. Set to true for complete conversation history.',
5
+ include_logs: 'Include logs for the session. Default: false. Use logs_page and logs_per_page for pagination.',
6
+ logs_page: 'Page number for logs pagination. Default: 1',
7
+ logs_per_page: 'Number of logs per page (1-100). Default: 25',
8
+ include_subagent_transcripts: 'Include subagent transcripts for the session. Default: false. Use transcripts_page and transcripts_per_page for pagination.',
9
+ transcripts_page: 'Page number for subagent transcripts pagination. Default: 1',
10
+ transcripts_per_page: 'Number of subagent transcripts per page (1-100). Default: 25',
11
+ };
12
+ export const GetSessionSchema = z.object({
13
+ id: z.union([z.string(), z.number()]).describe(PARAM_DESCRIPTIONS.id),
14
+ include_transcript: z.boolean().optional().describe(PARAM_DESCRIPTIONS.include_transcript),
15
+ include_logs: z.boolean().optional().describe(PARAM_DESCRIPTIONS.include_logs),
16
+ logs_page: z.number().min(1).optional().describe(PARAM_DESCRIPTIONS.logs_page),
17
+ logs_per_page: z.number().min(1).max(100).optional().describe(PARAM_DESCRIPTIONS.logs_per_page),
18
+ include_subagent_transcripts: z
19
+ .boolean()
20
+ .optional()
21
+ .describe(PARAM_DESCRIPTIONS.include_subagent_transcripts),
22
+ transcripts_page: z.number().min(1).optional().describe(PARAM_DESCRIPTIONS.transcripts_page),
23
+ transcripts_per_page: z
24
+ .number()
25
+ .min(1)
26
+ .max(100)
27
+ .optional()
28
+ .describe(PARAM_DESCRIPTIONS.transcripts_per_page),
29
+ });
30
+ const TOOL_DESCRIPTION = `Get detailed information about a specific agent session.
31
+
32
+ **Returns:** Complete session details including status, configuration, metadata, and optionally:
33
+ - Full session transcript
34
+ - Session logs (paginated)
35
+ - Subagent transcripts (paginated)
36
+
37
+ **Use cases:**
38
+ - View detailed session information
39
+ - Check session status and progress
40
+ - Retrieve session transcript for review
41
+ - Review logs for debugging
42
+ - Inspect subagent transcripts`;
43
+ function formatSessionDetails(session, includeTranscript) {
44
+ const lines = [
45
+ `## Session: ${session.title}`,
46
+ '',
47
+ '### Basic Information',
48
+ `- **ID:** ${session.id}`,
49
+ `- **Status:** ${session.status}`,
50
+ `- **Agent Type:** ${session.agent_type}`,
51
+ ];
52
+ if (session.slug)
53
+ lines.push(`- **Slug:** ${session.slug}`);
54
+ lines.push('');
55
+ lines.push('### Git Configuration');
56
+ if (session.git_root)
57
+ lines.push(`- **Repository:** ${session.git_root}`);
58
+ if (session.branch)
59
+ lines.push(`- **Branch:** ${session.branch}`);
60
+ if (session.subdirectory)
61
+ lines.push(`- **Subdirectory:** ${session.subdirectory}`);
62
+ lines.push('');
63
+ lines.push('### Execution');
64
+ lines.push(`- **Execution Provider:** ${session.execution_provider}`);
65
+ if (session.stop_condition)
66
+ lines.push(`- **Stop Condition:** ${session.stop_condition}`);
67
+ if (session.mcp_servers && session.mcp_servers.length > 0) {
68
+ lines.push(`- **MCP Servers:** ${session.mcp_servers.join(', ')}`);
69
+ }
70
+ if (session.prompt) {
71
+ lines.push('');
72
+ lines.push('### Current Prompt');
73
+ lines.push('```');
74
+ lines.push(session.prompt);
75
+ lines.push('```');
76
+ }
77
+ lines.push('');
78
+ lines.push('### Job Information');
79
+ if (session.session_id)
80
+ lines.push(`- **Claude Session ID:** ${session.session_id}`);
81
+ if (session.job_id)
82
+ lines.push(`- **Initial Job ID:** ${session.job_id}`);
83
+ if (session.running_job_id)
84
+ lines.push(`- **Running Job ID:** ${session.running_job_id}`);
85
+ if (Object.keys(session.metadata).length > 0) {
86
+ lines.push('');
87
+ lines.push('### System Metadata');
88
+ lines.push('```json');
89
+ lines.push(JSON.stringify(session.metadata, null, 2));
90
+ lines.push('```');
91
+ }
92
+ if (Object.keys(session.custom_metadata).length > 0) {
93
+ lines.push('');
94
+ lines.push('### Custom Metadata');
95
+ lines.push('```json');
96
+ lines.push(JSON.stringify(session.custom_metadata, null, 2));
97
+ lines.push('```');
98
+ }
99
+ lines.push('');
100
+ lines.push('### Timestamps');
101
+ lines.push(`- **Created:** ${session.created_at}`);
102
+ lines.push(`- **Updated:** ${session.updated_at}`);
103
+ if (session.archived_at)
104
+ lines.push(`- **Archived:** ${session.archived_at}`);
105
+ if (includeTranscript && session.transcript) {
106
+ lines.push('');
107
+ lines.push('### Transcript');
108
+ lines.push('```');
109
+ lines.push(session.transcript);
110
+ lines.push('```');
111
+ }
112
+ return lines.join('\n');
113
+ }
114
+ function formatLogs(logs, pagination) {
115
+ const lines = [
116
+ '',
117
+ '---',
118
+ `### Logs (${pagination.total_count} total, page ${pagination.page} of ${pagination.total_pages})`,
119
+ '',
120
+ ];
121
+ if (logs.length === 0) {
122
+ lines.push('No logs found.');
123
+ }
124
+ else {
125
+ logs.forEach((log) => {
126
+ const levelIcons = {
127
+ debug: '🔍',
128
+ info: 'â„šī¸',
129
+ warning: 'âš ī¸',
130
+ error: '❌',
131
+ verbose: '📝',
132
+ };
133
+ const icon = levelIcons[log.level] || '📝';
134
+ lines.push(`${icon} **[${log.level.toUpperCase()}]** ${log.created_at}`);
135
+ lines.push(` ${log.content}`);
136
+ lines.push('');
137
+ });
138
+ }
139
+ if (pagination.page < pagination.total_pages) {
140
+ lines.push(`*More logs available. Use logs_page=${pagination.page + 1} to see the next page.*`);
141
+ }
142
+ return lines.join('\n');
143
+ }
144
+ function formatSubagentTranscripts(transcripts, pagination) {
145
+ const lines = [
146
+ '',
147
+ '---',
148
+ `### Subagent Transcripts (${pagination.total_count} total, page ${pagination.page} of ${pagination.total_pages})`,
149
+ '',
150
+ ];
151
+ if (transcripts.length === 0) {
152
+ lines.push('No subagent transcripts found.');
153
+ }
154
+ else {
155
+ transcripts.forEach((transcript) => {
156
+ const statusIcons = {
157
+ running: '🔄',
158
+ completed: '✅',
159
+ failed: '❌',
160
+ };
161
+ const icon = transcript.status ? statusIcons[transcript.status] || '📝' : '📝';
162
+ const label = transcript.display_label || transcript.agent_id;
163
+ const statusText = transcript.status || 'unknown';
164
+ lines.push(`${icon} **${label}** (${statusText})`);
165
+ if (transcript.description)
166
+ lines.push(` ${transcript.description}`);
167
+ if (transcript.subagent_type)
168
+ lines.push(` Type: ${transcript.subagent_type}`);
169
+ lines.push(` Created: ${transcript.created_at}`);
170
+ lines.push('');
171
+ });
172
+ }
173
+ if (pagination.page < pagination.total_pages) {
174
+ lines.push(`*More transcripts available. Use transcripts_page=${pagination.page + 1} to see the next page.*`);
175
+ }
176
+ return lines.join('\n');
177
+ }
178
+ export function getSessionTool(_server, clientFactory) {
179
+ return {
180
+ name: 'get_session',
181
+ description: TOOL_DESCRIPTION,
182
+ inputSchema: {
183
+ type: 'object',
184
+ properties: {
185
+ id: {
186
+ oneOf: [{ type: 'string' }, { type: 'number' }],
187
+ description: PARAM_DESCRIPTIONS.id,
188
+ },
189
+ include_transcript: {
190
+ type: 'boolean',
191
+ description: PARAM_DESCRIPTIONS.include_transcript,
192
+ },
193
+ include_logs: {
194
+ type: 'boolean',
195
+ description: PARAM_DESCRIPTIONS.include_logs,
196
+ },
197
+ logs_page: {
198
+ type: 'number',
199
+ minimum: 1,
200
+ description: PARAM_DESCRIPTIONS.logs_page,
201
+ },
202
+ logs_per_page: {
203
+ type: 'number',
204
+ minimum: 1,
205
+ maximum: 100,
206
+ description: PARAM_DESCRIPTIONS.logs_per_page,
207
+ },
208
+ include_subagent_transcripts: {
209
+ type: 'boolean',
210
+ description: PARAM_DESCRIPTIONS.include_subagent_transcripts,
211
+ },
212
+ transcripts_page: {
213
+ type: 'number',
214
+ minimum: 1,
215
+ description: PARAM_DESCRIPTIONS.transcripts_page,
216
+ },
217
+ transcripts_per_page: {
218
+ type: 'number',
219
+ minimum: 1,
220
+ maximum: 100,
221
+ description: PARAM_DESCRIPTIONS.transcripts_per_page,
222
+ },
223
+ },
224
+ required: ['id'],
225
+ },
226
+ handler: async (args) => {
227
+ try {
228
+ const validatedArgs = GetSessionSchema.parse(args);
229
+ const client = clientFactory();
230
+ // Get session details
231
+ const session = await client.getSession(validatedArgs.id, validatedArgs.include_transcript);
232
+ let output = formatSessionDetails(session, validatedArgs.include_transcript || false);
233
+ // Get logs if requested
234
+ if (validatedArgs.include_logs) {
235
+ const logsResponse = await client.listLogs(session.id, {
236
+ page: validatedArgs.logs_page,
237
+ per_page: validatedArgs.logs_per_page,
238
+ });
239
+ output += formatLogs(logsResponse.logs, logsResponse.pagination);
240
+ }
241
+ // Get subagent transcripts if requested
242
+ if (validatedArgs.include_subagent_transcripts) {
243
+ const transcriptsResponse = await client.listSubagentTranscripts(session.id, {
244
+ page: validatedArgs.transcripts_page,
245
+ per_page: validatedArgs.transcripts_per_page,
246
+ });
247
+ output += formatSubagentTranscripts(transcriptsResponse.subagent_transcripts, transcriptsResponse.pagination);
248
+ }
249
+ return {
250
+ content: [
251
+ {
252
+ type: 'text',
253
+ text: output,
254
+ },
255
+ ],
256
+ };
257
+ }
258
+ catch (error) {
259
+ return {
260
+ content: [
261
+ {
262
+ type: 'text',
263
+ text: `Error getting session: ${error instanceof Error ? error.message : 'Unknown error'}`,
264
+ },
265
+ ],
266
+ isError: true,
267
+ };
268
+ }
269
+ },
270
+ };
271
+ }