Repository navigation
Expand file tree
/
Copy path04-mcp-weather.ts
More file actions
79 lines (73 loc) · 2.62 KB
/
Copy path04-mcp-weather.ts
File metadata and controls
79 lines (73 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* MCP Weather — using Conductor's MCP system tasks for live weather.
*
* Demonstrates the mcpTool() function which uses Conductor's built-in
* LIST_MCP_TOOLS and CALL_MCP_TOOL system tasks. The MCP test server
* provides deterministic weather data, and the Conductor server handles all
* MCP protocol communication — no worker process needed.
*
* Flow:
* ListMcpTools -> LLM (picks tool) -> CallMcpTool -> Final LLM
*
* MCP Test Server Setup (mcp-testkit):
* pip install mcp-testkit
*
* # Start without auth:
* mcp-testkit --transport http
*
* # Or start with auth (requires storing the secret as a credential):
* mcp-testkit --transport http --auth <secret>
*
* # Store credentials via CLI or Agentspan UI:
* conductor secret put MCP_TEST_API_KEY <secret>
*
* Requirements:
* - Conductor server with LLM support
* - mcp-testkit running on http://localhost:3001 (see setup above)
* - CONDUCTOR_SERVER_URL=http://localhost:8080/api
* - CONDUCTOR_AGENT_LLM_MODEL=openai/gpt-4o-mini
*/
import { Agent, AgentRuntime, mcpTool } from '@io-orkes/conductor-javascript/agents';
import { llmModel } from './settings';
// Create MCP tool — Conductor discovers tools from mcp-testkit at runtime
// ${MCP_TEST_API_KEY} is resolved server-side from the credential store.
const weather = mcpTool({
serverUrl: 'http://localhost:3001/mcp',
name: 'weather_mcp',
description:
'Weather and air quality tools via MCP, use it to get current and historical weather information for a city',
headers: { Authorization: 'Bearer ${MCP_TEST_API_KEY}' },
credentials: ['MCP_TEST_API_KEY'],
});
export const agent = new Agent({
name: 'weather_mcp_agent',
model: llmModel,
maxTokens: 10240,
tools: [weather],
instructions:
'You are a weather assistant. Use the available MCP tools ' +
'to answer questions about weather conditions around the world.' +
'when asked get the current temperature in F' +
'use the tools provided',
});
async function main() {
const runtime = new AgentRuntime();
try {
const result = await runtime.run(
agent,
"What's the weather like in San Francisco (CA) right now?",
);
result.printResult();
// Production pattern:
// 1. Deploy once during CI/CD (optional -- serve() below also deploys):
// await runtime.deploy(agent);
// CLI alternative:
// conductor deploy --package examples/agents --agents weather_mcp_agent
//
// 2. In a separate long-lived worker process (deploys + registers workers + starts polling):
// await runtime.serve(agent);
} finally {
await runtime.shutdown();
}
}
main().catch(console.error);