mcp
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| CallToolResult pyt3client.mcp MCP `tools/call` result. |
||
| ContentBlock pyt3client.mcp One block of a tool result. T3 Code answers with a single JSON `text` block. |
||
| McpHttpSession pyt3client.mcp One MCP session against a T3 Code environment's `/mcp`. |
||
| T3AuthError pyt3client.errors Signing in failed, or the server no longer accepts the credential. |
||
| T3HttpError pyt3client.errors The server answered with an unexpected HTTP status. |
||
| T3McpError pyt3client.errors The server answered a request with a JSON-RPC error. |
||
| T3ProtocolError pyt3client.errors The server answered in a shape this client does not understand. |
||
| ToolAnnotations pyt3client.mcp |
||
| ToolInfo pyt3client.mcp One entry of `tools/list`. |
||
| _JsonRpcError pyt3client.mcp |
||
| _JsonRpcResponse pyt3client.mcp |
🛈 DocStrings¶
Minimal MCP Streamable HTTP client, just enough for T3 Code's /mcp.
T3 Code needs only initialize, tools/list and tools/call, with no
sampling, elicitation or server-initiated requests, so this speaks that subset
directly over httpx rather than pulling in a full MCP SDK. It mirrors upstream's
own client for linked environments, apps/server/src/peer/PeerMcpClient.ts
(https://github.com/pingdotgg/t3code):
- POST JSON-RPC to
/mcpwithaccept: application/json, text/event-stream. initializeanswers with anmcp-session-idheader; later requests send it plusmcp-protocol-version. The server returns 400 without that header.- Sessions live in server memory, so after a server restart a request gets 404. The session is then opened again and the request retried once.
- Requests must not carry an
Originheader:/mcpanswers 403 to anything that looks like a browser (apps/server/src/mcp/McpHttpServer.ts). httpx sends none by default.
PROTOCOL_VERSION
module-attribute
¶
PROTOCOL_VERSION = '2025-06-18'
MCP revision T3 Code speaks (PROTOCOL_VERSION in upstream PeerMcpClient.ts).
CallToolResult
¶
Bases: BaseModel
MCP tools/call result.
Source code in src/pyt3client/mcp.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
ContentBlock
¶
Bases: BaseModel
One block of a tool result. T3 Code answers with a single JSON text block.
Source code in src/pyt3client/mcp.py
58 59 60 61 62 63 64 | |
McpHttpSession
¶
One MCP session against a T3 Code environment's /mcp.
Safe for concurrent use: requests are independent HTTP POSTs, and the session is opened once, lazily, under a lock.
Source code in src/pyt3client/mcp.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
server_info
instance-attribute
¶
server_info: dict[str, JsonValue] | None = None
serverInfo from initialize, such as {"name": "T3 Code", "version": ...}.
__init__
¶
__init__(
url: str,
token: SecretStr,
*,
http_client: AsyncClient,
headers: Mapping[str, str] | None = None,
client_name: str = "pyt3client",
client_version: str = "0"
) -> None
Create a session; nothing is sent until the first request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Full |
required |
token
|
SecretStr
|
Bearer token for the endpoint. |
required |
http_client
|
AsyncClient
|
Client used for every request; owned by the caller. |
required |
headers
|
Mapping[str, str] | None
|
Extra headers sent with every request (such as |
None
|
client_name
|
str
|
|
'pyt3client'
|
client_version
|
str
|
|
'0'
|
Source code in src/pyt3client/mcp.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
call_tool
async
¶
call_tool(
name: str, arguments: Mapping[str, JsonValue], *, timeout: float | None = None
) -> CallToolResult
Call a tool and return the raw MCP result (refusals are not raised here).
Source code in src/pyt3client/mcp.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | |
close
async
¶
close() -> None
End the session on the server (best effort).
Source code in src/pyt3client/mcp.py
325 326 327 328 329 330 331 332 333 334 | |
list_tools
async
¶
list_tools() -> list[ToolInfo]
All tools the server offers this credential, following pagination.
Source code in src/pyt3client/mcp.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
request
async
¶
request(
method: str, params: Mapping[str, JsonValue] | None = None, *, timeout: float | None = None
) -> dict[str, JsonValue]
Send one JSON-RPC request and return its result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
str
|
JSON-RPC method, such as |
required |
params
|
Mapping[str, JsonValue] | None
|
Request params. |
None
|
timeout
|
float | None
|
Read timeout in seconds for this request; the client's default otherwise. |
None
|
Raises:
| Type | Description |
|---|---|
T3AuthError
|
The token was rejected (HTTP 401). |
T3McpError
|
The server answered with a JSON-RPC error. |
T3HttpError
|
Any other unexpected HTTP status. |
T3ProtocolError
|
The response could not be read. |
Source code in src/pyt3client/mcp.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
ToolInfo
¶
Bases: BaseModel
One entry of tools/list.
Source code in src/pyt3client/mcp.py
92 93 94 95 96 97 98 99 100 101 102 | |