Skip to main content

Declare a tool

Every pack is built from declarations like this one. This is Gmail’s messages_list, written out by hand.
1

Describe the arguments

list_messages.py
Each field says where it belongs in the request. Query() makes it a query parameter; Path() interpolates it into the URL template instead.
2

Build a factory

The factory carries everything shared across the tools of one API: the base URL, the credential, and the conventions the API’s wire format follows.
list_messages.py
For an API that authenticates with a header instead of a bearer token, api_key_tool_factory takes the same arguments.
3

Declare the tool

Assign the arguments a target endpoint. The marked line is the model’s half.
list_messages.py
4

Call it

list_messages.py
That sends GET gmail/v1/users/me/messages?q=is:unread&maxResults=5 with the token attached, and returns the parsed body. Spelling the parameter Gmail’s way on the wire is what query_case did, and it is part of the casing cascade.A declaration also carries wire format, field policy and failure that arrives as HTTP 200. The wire contract is where those go.

See what the model sees

Before wiring a tool into an agent, print the boundary. It is computed from the same declarations the runtime executes, so it cannot drift from what actually happens.
egress_map.py

Call a pack

A pack is the tools of one API, already declared. Configure the credential once and every tool in it is callable.
quickstart.py
A static access token is fine for a script and useless for a product, because it expires in about an hour. See authorization servers for refresh against any OAuth 2.0 token endpoint, and getting the grant for where the refresh token comes from.

Hand it to a framework

Every pack exports TOOLS, and a list of your own declarations works the same way. An adapter turns either into what the framework expects.
The OpenAI format needs nothing beyond the core. LangChain needs pip install 'charter[langchain]'. Client configuration for the MCP server is on its page, and the other two on adapters.

Next steps

The wire contract

Body format, static parameters, per-call headers, pagination.

Authentication

OAuth refresh against any token endpoint, and one set of tools for many users.