Rebasely Beta: data may be purged

examples/MCP-tools Public

Limit tool calls per client with a Durable Object #1

Changed files

21 files changed335 additions21 deletionssince main at fcaf000

An agent calling a tool

2 steps added

  • Added
  • Rerouted, relabelled or moved
  • Removed

A model asks for the time in Tokyo. Its MCP client connects, lists the tools and calls time_in_zone. Every message is its own POST to /mcp, answered by a fresh server.

An agent calling a tool: 16 steps between 7 participants Step 1: agent to mcp-client, needs the current time in Tokyoneeds the current time in Tok…Step 2: mcp-client to mcp-server, POST /mcp: initializePOST /mcp: initializeStep 3: mcp-server to mcp-client, server info and the tools capabilityserver info and the tools cap…Step 4: mcp-client to mcp-server, POST /mcp: tools/listPOST /mcp: tools/listStep 5: mcp-server to tools, read each tool's name, description and schemasread each tool's name, descri…Step 6: mcp-server to mcp-client, three tools with JSON Schema inputs and outputsthree tools with JSON Schema …Step 7: agent to mcp-client, call time_in_zone with zone tokyocall time_in_zone with zone t…Step 8: mcp-client to mcp-server, POST /mcp: tools/call time_in_zonePOST /mcp: tools/call time_in…Step 9: mcp-server to mcp-sdk, check the arguments against the input schemacheck the arguments against the input schemaStep 10: mcp-server to rate-limiter, take a token from this client's bucket (added)take a token from this client's bucketStep 11: rate-limiter to mcp-server, allowed, 29 tokens left (added)allowed, 29 tokens leftStep 12: mcp-server to tools, run it: resolve tokyo to Asia/Tokyo, read the offsetrun it: resolve tokyo to Asia…Step 13: tools to mcp-server, local time, or a ToolError saying what to fixlocal time, or a ToolError sa…Step 14: mcp-server to mcp-client, structuredContent and JSON text, isError on failurestructuredContent and JSON te…Step 15: mcp-server to usage, count the call for today, after the responsecount the call for today, after the responseStep 16: mcp-client to agent, the result as a tool messagethe result as a tool messageagentagentActormcp-clientmcp-clientActormcp-servermcp-serverWorkertoolstoolsLibrarymcp-sdkmcp-sdkExternalrate-limiter (added in this flow)rate-limiterDurable Object · addedusageusageKV namespace

The flow tool-call at the head of this pull request, numbered in its order, with the steps it adds, reroutes, relabels, moves and removes. A removed step has no number.

Steps

  1. Step 1: agent → mcp-client needs the current time in Tokyo
  2. Step 2: mcp-client → mcp-server POST /mcp: initialize
  3. Step 3: mcp-server → mcp-client server info and the tools capability
  4. Step 4: mcp-client → mcp-server POST /mcp: tools/list
  5. Step 5: mcp-server → tools read each tool's name, description and schemas
  6. Step 6: mcp-server → mcp-client three tools with JSON Schema inputs and outputs
  7. Step 7: agent → mcp-client call time_in_zone with zone tokyo
  8. Step 8: mcp-client → mcp-server POST /mcp: tools/call time_in_zone
  9. Step 9: mcp-server → mcp-sdk check the arguments against the input schema
  10. Step 10, added: mcp-server → rate-limiter take a token from this client's bucket Added
  11. Step 11, added: rate-limiter → mcp-server allowed, 29 tokens left Added
  12. Step 12: mcp-server → tools run it: resolve tokyo to Asia/Tokyo, read the offset
  13. Step 13: tools → mcp-server local time, or a ToolError saying what to fix
  14. Step 14: mcp-server → mcp-client structuredContent and JSON text, isError on failure
  15. Step 15: mcp-server → usage count the call for today, after the response
  16. Step 16: mcp-client → agent the result as a tool message

Knowledge base

Back to the conversation