File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { errorMessage } from "../../core/src/error"
1111import { setConsoleColors } from "../../core/src/consolecolor"
1212import { startProjectWatcher } from "./watch"
1313import { applyRemoteOptions , RemoteOptions } from "./remote"
14+ import { setMcpMode } from "../../core/src/mcp"
1415
1516/**
1617 * Starts the MCP server.
@@ -26,6 +27,7 @@ export async function startMcpServer(
2627) {
2728 setConsoleColors ( false )
2829 logVerbose ( `mcp server: starting...` )
30+ setMcpMode ( "server" )
2931
3032 await applyRemoteOptions ( options )
3133
Original file line number Diff line number Diff line change 1+ import debug from "debug"
2+ const dbg = debug ( "genaiscript:mcp" )
3+ export let mcpMode : "server" | "client" = undefined
4+
5+ export function setMcpMode ( mode : "server" | "client" ) {
6+ if ( mcpMode && mcpMode !== mode ) {
7+ throw new Error (
8+ `MCP mode already set to ${ mcpMode } . Cannot change to ${ mode } `
9+ )
10+ }
11+ mcpMode = mode
12+ dbg ( `mode: ${ mode } ` )
13+ }
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { errorMessage } from "./error"
1212import { CancellationOptions , toSignal } from "./cancellation"
1313import type { ProgressCallback } from "@modelcontextprotocol/sdk/shared/protocol.js"
1414import { deleteUndefinedValues } from "./cleaners"
15+ import { setMcpMode } from "./mcp"
1516
1617export class McpClientManager extends EventTarget implements AsyncDisposable {
1718 readonly options : TraceOptions
@@ -31,6 +32,7 @@ export class McpClientManager extends EventTarget implements AsyncDisposable {
3132 dbgc ( `starting ${ id } ` )
3233 const trace = this . options . trace . startTraceDetails ( `🪚 mcp ${ id } ` )
3334 try {
35+ setMcpMode ( "client" )
3436 const { Client } = await import (
3537 "@modelcontextprotocol/sdk/client/index.js"
3638 )
You can’t perform that action at this time.
0 commit comments