Redis Context Gateway quickstart
Discover and call Context Gateway tools with Python, TypeScript, or the Iris CLI in search or full mode.
Discover tools and query a sample clinic directory through Redis Context Gateway using Python, TypeScript, or the Iris command-line interface (CLI).
You’ll find a tool for filtering healthcare providers, inspect its inputs, and use it to find cardiologists. Choose Search mode to discover relevant tools on demand, or Full mode to list available tools.
Python and CLI examples use the unified redis-iris package. TypeScript examples use the separate @redis-iris/context-gateway package. You don’t need an agent framework or a model-provider API key.
Before you begin
You need a Gateway with the sample clinic directory registered as a Context Surface, its Model Context Protocol (MCP) endpoint, and an agent key with permission to use it. Follow the sample setup guide, or ask your administrator for a prepared sample.
The setup guide creates two Gateways. Choose Operations for search mode or Front desk for full mode. You only need one endpoint for this walkthrough. Selecting a documentation option does not change the Gateway’s configuration.
The directory contains three cardiologists: two at clinic-a and one at clinic-b. Compression is not required for this query.
1. Install the client
Choose a client and use it throughout the walkthrough. Changing a client dropdown updates the other client dropdowns on this page. The Search/Full mode choice is independent.
Use Python 3.11 or later.
python -m venv .venv
source .venv/bin/activate
pip install redis-iris
2. Configure the connection
Set the endpoint and key for the Gateway you chose:
export IRIS_CONTEXT_GATEWAY_URL='<gateway-mcp-endpoint>'
export IRIS_CONTEXT_GATEWAY_API_KEY='<agent-key>'
Use the returned mcpEndpoint, not the administration URL. The Redis SDKs require HTTPS except for local development on a loopback address such as localhost. Keep your key out of source control and model prompts.
The snippets explain each step of the complete examples. Use those programs to run the walkthrough without assembling fragments.
import json
from redis_iris import ContextGateway
gateway = ContextGateway.from_env()
from_env() reads the connection values. The SDK manages MCP sessions for discovery and calls.
3. Discover a tool
Choose the mode configured on your Gateway. In the results, look for scheduling__filter_provider.
Search matches words in tool names, titles, and descriptions. This example searches for the sample filter.
Python
tools = gateway.search("filter_provider")
for tool in tools:
print(tool.name, tool.description)
TypeScript
const found = await client.callTool({
name: "search_tools",
arguments: { query: "filter_provider", limit: 5 },
});
if (found.isError) throw new Error(JSON.stringify(found.content));
const data = found.structuredContent as { tools?: ToolDefinition[] } | undefined;
if (!Array.isArray(data?.tools)) throw new Error("Search returned no tool definitions.");
const tools = data.tools;
ToolDefinition is a local type declared in the complete example.
CLI
iris --json context-gateway tools search filter_provider
4. Inspect the tool
The input schema describes the arguments the tool accepts. You’ll use tag_conditions to match the specialty field and limit to bound the number of returned records.
provider_filter = next(
(tool for tool in tools if tool.name == "scheduling__filter_provider"),
None,
)
if provider_filter is None:
raise RuntimeError("The sample tool was not found. Check the scheduling Upstream.")
print(json.dumps(provider_filter.input_schema, indent=2))
5. Find cardiologists
Python and CLI use the same call in either mode. TypeScript uses the MCP session directly: call run_tool with the discovered identity in search mode, or call the tool’s name in full mode.
result = gateway.call(
provider_filter.name,
tag_conditions=[{"field": "specialty", "value": "cardiology"}],
limit=100,
)
if result.is_error:
raise RuntimeError(result.as_text())
print(json.dumps(result.data, indent=2))
Check the tool’s error flag before using its result. Connection and protocol failures can also raise exceptions. See Limits and errors.
6. Check the result
With the sample data, the result contains three providers whose specialty is cardiology:
| Clinic | Matching providers |
|---|---|
clinic-a |
2 |
clinic-b |
1 |
Python exposes the returned data through result.data. TypeScript and CLI return MCP responses containing structured content and text content.
You’ve discovered and called a tool through Context Gateway. An agent can use the same tool definitions and results to answer questions about the directory.
Complete examples
Run one program using the connection values you set. Each defaults to search mode. Selecting a mode in the program does not reconfigure the Gateway.
Save as quickstart.py. Change mode to "full" for a full-mode Gateway. Run python quickstart.py.
import json
from redis_iris import ContextGateway
gateway = ContextGateway.from_env()
mode = "search" # Use "full" for a full-mode Gateway.
if mode == "search":
tools = gateway.search("filter_provider")
elif mode == "full":
tools = gateway.tools()
else:
raise ValueError("Choose search or full mode.")
for tool in tools:
print(tool.name, tool.description)
provider_filter = next(
(tool for tool in tools if tool.name == "scheduling__filter_provider"),
None,
)
if provider_filter is None:
raise RuntimeError("The sample tool was not found. Check the scheduling Upstream.")
print(json.dumps(provider_filter.input_schema, indent=2))
result = gateway.call(
provider_filter.name,
tag_conditions=[{"field": "specialty", "value": "cardiology"}],
limit=100,
)
if result.is_error:
raise RuntimeError(result.as_text())
print(json.dumps(result.data, indent=2))
Troubleshooting
| Problem | What to check |
|---|---|
| Connection or authentication fails | Check the MCP endpoint, key, and the key’s access to this Gateway. |
| Search reports that the Gateway is in full mode | Use the Full mode example or the search-mode endpoint. |
| The sample tool is missing | Confirm that the scheduling Context Surface is enabled and its catalog contains filter_provider. |
| No records match | Confirm that the sample data is loaded and indexing has completed. |
See Limits and errors for further troubleshooting.
Next steps
- Integrate with an agent: Connect the Gateway to an agent framework.
- Manage Gateways and Upstreams: Add tool sources and configure caching and compression.
- Connect with MCP: Work directly with sessions and stored results.