| 508 | * Truncates server instructions if they exceed MAX_MCP_DESCRIPTION_LENGTH. |
| 509 | */ |
| 510 | export function buildConnectedServer( |
| 511 | options: BuildConnectedServerOptions, |
| 512 | logger: McpClientDependencies['logger'], |
| 513 | ): ConnectedMCPServer { |
| 514 | const { name, client, config, cleanup } = options |
| 515 | |
| 516 | const capabilities = client.getServerCapabilities() ?? {} |
| 517 | const serverVersion = client.getServerVersion() |
| 518 | const rawInstructions = client.getInstructions() |
| 519 | |
| 520 | let instructions = rawInstructions |
| 521 | if (rawInstructions && rawInstructions.length > MAX_MCP_DESCRIPTION_LENGTH) { |
| 522 | instructions = |
| 523 | rawInstructions.slice(0, MAX_MCP_DESCRIPTION_LENGTH) + '… [truncated]' |
| 524 | logger.debug( |
| 525 | `[${name}] Server instructions truncated from ${rawInstructions.length} to ${MAX_MCP_DESCRIPTION_LENGTH} chars`, |
| 526 | ) |
| 527 | } |
| 528 | |
| 529 | return { |
| 530 | name, |
| 531 | client, |
| 532 | type: 'connected' as const, |
| 533 | capabilities, |
| 534 | serverInfo: serverVersion, |
| 535 | instructions, |
| 536 | config, |
| 537 | cleanup, |
| 538 | } |
| 539 | } |