Commit da74f4b
Add Python example for create_with_server_id fix (#9)
Land examples/api/create_by_server_id.py, third of the seven
create_by_* examples and the first of the four routing variants
added in gopher-orch 0.1.23. Direct port of
gopher-mcp-js/examples/api/create_by_server_id.ts, which itself
ports gopher-orch/examples/sdk/api/create_by_server_id.cc.
Behaviour:
- Scopes the agent to a single MCP server in the caller's workspace
by id. Internally hits the same GET /v1/mcp-servers endpoint as
create_with_api_key under the Bearer api key, but adds the
"?serverId={id}" routing query so the response carries only the
matching server entry. Use this when the api key owns several
MCP servers but the agent should bind to exactly one.
- Provider defaults to AnthropicProvider; the model comes from the
LLM_MODEL env var. Refuses to call the FFI when any of the three
required env vars (LLM_MODEL, GOPHER_API_KEY, GOPHER_MCP_SERVER_ID)
is still the placeholder, printing a clear error to stderr and
exiting 1.
- Reads the routing parameter from GOPHER_MCP_SERVER_ID,
matching the JS sibling's env-var name so a downstream user can
share env across the JS and Python toolchains. Same pattern for
the next three routing variants (server_name, gateway_id,
gateway_name).
- Accepts queries as positional argv with the canned "What time is
it in Tokyo?" fallback. try / finally with agent.dispose() so the
native handle is always released.
Requires the create_with_server_id factory landed earlier in this
PR series; against the vendored 0.1.1 dylib the example exits with
an AgentError from the null-handle pump because the C symbol is
missing. Against a fresh gopher-orch 0.1.23 build the example
completes end-to-end.
Verified locally: placeholder refusal path exits 1 with a clear
diagnostic; syntax check clean; no forbidden tokens.1 parent c454665 commit da74f4b
1 file changed
Lines changed: 116 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
0 commit comments