@@ -17,23 +17,59 @@ import { HandlerFunction, McpTool } from './types';
1717export { McpOptions } from './options' ;
1818export { ClientOptions } from 'conductor-node' ;
1919
20- export const newMcpServer = ( ) =>
20+ async function getInstructions ( ) {
21+ // This API key is optional; providing it allows the server to fetch instructions for unreleased versions.
22+ const stainlessAPIKey = readEnv ( 'STAINLESS_API_KEY' ) ;
23+ const response = await fetch (
24+ readEnv ( 'CODE_MODE_INSTRUCTIONS_URL' ) ?? 'https://api.stainless.com/api/ai/instructions/conductor' ,
25+ {
26+ method : 'GET' ,
27+ headers : { ...( stainlessAPIKey && { Authorization : stainlessAPIKey } ) } ,
28+ } ,
29+ ) ;
30+
31+ let instructions : string | undefined ;
32+ if ( ! response . ok ) {
33+ console . warn (
34+ 'Warning: failed to retrieve MCP server instructions. Proceeding with default instructions...' ,
35+ ) ;
36+
37+ instructions = `
38+ This is the conductor MCP server. You will use Code Mode to help the user perform
39+ actions. You can use search_docs tool to learn about how to take action with this server. Then,
40+ you will write TypeScript code using the execute tool take action. It is CRITICAL that you be
41+ thoughtful and deliberate when executing code. Always try to entirely solve the problem in code
42+ block: it can be as long as you need to get the job done!
43+ ` ;
44+ }
45+
46+ instructions ??= ( ( await response . json ( ) ) as { instructions : string } ) . instructions ;
47+ instructions = `
48+ The current time in Unix timestamps is ${ Date . now ( ) } .
49+
50+ ${ instructions }
51+ ` ;
52+
53+ return instructions ;
54+ }
55+
56+ export const newMcpServer = async ( ) =>
2157 new McpServer (
2258 {
2359 name : 'conductor_node_api' ,
2460 version : '14.5.0' ,
2561 } ,
26- { capabilities : { tools : { } , logging : { } } } ,
62+ {
63+ instructions : await getInstructions ( ) ,
64+ capabilities : { tools : { } , logging : { } } ,
65+ } ,
2766 ) ;
2867
29- // Create server instance
30- export const server = newMcpServer ( ) ;
31-
3268/**
3369 * Initializes the provided MCP Server with the given tools and handlers.
3470 * If not provided, the default client, tools and handlers will be used.
3571 */
36- export function initMcpServer ( params : {
72+ export async function initMcpServer ( params : {
3773 server : Server | McpServer ;
3874 clientOptions ?: ClientOptions ;
3975 mcpOptions ?: McpOptions ;
0 commit comments