You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mcp-agent-sdk/core-components/configuring-your-application.mdx
+70-6Lines changed: 70 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,20 +7,22 @@ icon: gear
7
7
8
8
mcp-agent uses YAML configuration files to manage application settings, MCP servers, and model providers.
9
9
10
-
## Configuration Files
10
+
## Configuration files
11
11
12
-
mcp-agent uses two configuration files:
12
+
Start with two YAML files at the root of your project:
13
13
14
14
<CardGroupcols={2}>
15
15
<Cardtitle="mcp_agent.config.yaml"icon="gear">
16
-
Application configuration, MCP servers, and non-sensitive settings
16
+
Application configuration, MCP servers, logging, execution engine, model defaults
17
17
</Card>
18
18
<Cardtitle="mcp_agent.secrets.yaml"icon="key">
19
-
API keys, secrets, and sensitive credentials (gitignored)
19
+
API keys, OAuth credentials, and other secrets (gitignored)
20
20
</Card>
21
21
</CardGroup>
22
22
23
-
## Basic Configuration
23
+
See [Specify Secrets](/mcp-agent-sdk/core-components/specify-secrets) for credential management patterns and production tips.
24
+
25
+
## Basic configuration
24
26
25
27
Here's a minimal configuration:
26
28
@@ -138,7 +140,7 @@ mcp:
138
140
139
141
## Model Providers
140
142
141
-
Configure your LLM provider:
143
+
Configure your LLM provider. Many examples follow this layout—for instance, the [basic finder agent](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/basic/mcp_basic_agent) sets OpenAI defaults exactly this way.
Pair this with secrets in `mcp_agent.secrets.yaml` or environment variables. For concrete walkthroughs, study the [OAuth basic agent](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/basic/oauth_basic_agent) and the [interactive OAuth tool](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/oauth/interactive_tool). The [pre-authorize workflow example](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/oauth/pre_authorize) shows how to seed credentials before a background workflow runs.
232
+
233
+
## Programmatic configuration
234
+
235
+
You can bypass file discovery by passing a fully-formed `Settings` object (or a path) to `MCPApp`. This is especially useful for tests and scripts that compose configuration dynamically.
236
+
237
+
```python
238
+
from mcp_agent.app import MCPApp
239
+
from mcp_agent.config import Settings, OpenAISettings
240
+
241
+
settings = Settings(
242
+
execution_engine="asyncio",
243
+
openai=OpenAISettings(
244
+
default_model="gpt-4o-mini",
245
+
temperature=0.3,
246
+
),
247
+
)
248
+
249
+
app = MCPApp(name="dynamic", settings=settings)
250
+
```
251
+
252
+
Because `Settings` extends `BaseSettings`, environment variables still override any fields you set explicitly.
253
+
254
+
## Configuration discovery
255
+
256
+
When `MCPApp` starts, it resolves settings in this order:
- `mcp_agent.config.yaml`(or `mcp-agent.config.yaml`) discovered in the working directory, parent directories, `.mcp-agent/` folders, or `~/.mcp-agent/`
260
+
- `mcp_agent.secrets.yaml`/ `mcp-agent.secrets.yaml` merged on top
261
+
- Environment variables (including values from `.env`, using `__` for nesting)
262
+
263
+
Environment variables override file-based values, while the preload option short-circuits everything else—handy for containerised deployments that mount secrets from a vault. [Specify Secrets](/mcp-agent-sdk/core-components/specify-secrets) covers strategies for each stage.
264
+
201
265
## Environment Variables
202
266
203
267
You can reference environment variables in configuration:
@@ -5,17 +5,141 @@ description: "Learn how to connect to MCP servers using the MCP server registry
5
5
icon: plug
6
6
---
7
7
8
-
<Info>
9
-
Content to be migrated covering MCP server registry, MCP connection manager, gen_client, connect/disconnect patterns.
10
-
</Info>
11
-
12
8
## Overview
13
9
14
-
mcp-agent provides multiple ways to connect to and manage MCP servers:
10
+
Every `MCPApp` initialises a `ServerRegistry` that knows how to start and authenticate each server defined in `mcp_agent.config.yaml`. The registry works hand in hand with `MCPConnectionManager` to provide two patterns:
11
+
12
+
- Short-lived connections using `gen_client`, perfect for one-off operations.
13
+
- Persistent connections managed by the connection manager, ideal for agents and long-running workflows.
14
+
15
+
Understanding these two layers lets you control connection reuse, lifecycle, and error handling with precision.
16
+
17
+
## Inspect configured servers
18
+
19
+
After `app.run()` the registry is accessible via the context:
20
+
21
+
```python
22
+
asyncwith app.run() as running_app:
23
+
registry = running_app.server_registry
24
+
for name, cfg in registry.registry.items():
25
+
running_app.logger.info(
26
+
"Server configured",
27
+
data={"name": name, "transport": cfg.transport},
28
+
)
29
+
```
30
+
31
+
The registry resolves transports (`stdio`, `sse`, `streamable_http`, `websocket`), applies authentication (`api_key` or OAuth), and exposes helpers such as `register_init_hook`.
32
+
33
+
## Ephemeral sessions with `gen_client`
34
+
35
+
Use `gen_client` when you need a connection for the duration of a `with` block. It spins up the server process (for stdio transports), performs initialisation, yields an `MCPAgentClientSession`, and tears everything down automatically—a handy pattern for scripts, CLI utilities, or inspection. The [basic finder agent](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/basic/mcp_basic_agent) uses the same underlying helpers when it initialises an agent.
36
+
37
+
```python
38
+
from mcp_agent.mcp.gen_client import gen_client
39
+
40
+
asyncwith app.run():
41
+
asyncwith gen_client(
42
+
server_name="fetch",
43
+
server_registry=app.server_registry,
44
+
context=app.context,
45
+
) as session:
46
+
tools =await session.list_tools()
47
+
print("Fetch tools:", [tool.name for tool in tools.tools])
48
+
```
49
+
50
+
This is the simplest way to script against MCP servers without committing to persistent connections.
51
+
52
+
## Persistent connections and connection pooling
53
+
54
+
The `ServerRegistry` owns a `MCPConnectionManager` (`registry.connection_manager`) that maintains long-lived connections in a background task group. You can either interact with it directly or rely on helpers such as `mcp_agent.mcp.gen_client.connect`.
55
+
56
+
```python
57
+
from mcp_agent.mcp.gen_client import connect, disconnect
Agents use the connection manager behind the scenes. Set `connection_persistence=True` (the default) to keep servers warm between tool calls or `False` to close the transport after each request.
83
+
84
+
```python
85
+
agent = Agent(
86
+
name="finder",
87
+
instruction="Use fetch and filesystem tools",
88
+
server_names=["fetch", "filesystem"],
89
+
connection_persistence=True,
90
+
context=app.context,
91
+
)
92
+
```
93
+
94
+
Persistent connections dramatically reduce latency when calling the same server repeatedly.
95
+
96
+
## Aggregating multiple servers
97
+
98
+
`MCPAggregator` builds a “server-of-servers” using the same registry and connection manager. You can namespace tool calls or expose a merged surface area:
99
+
100
+
```python
101
+
from mcp_agent.mcp.mcp_aggregator import MCPAggregator
This pattern mirrors the [`examples/basic/mcp_server_aggregator`](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/basic/mcp_server_aggregator) sample and is commonly used when turning an entire app into a single MCP server.
115
+
116
+
## OAuth-aware connections
117
+
118
+
When server definitions include `auth.oauth`, the registry and connection manager automatically coordinate with the app’s token manager. The OAuth examples highlight three recurring patterns:
119
+
120
+
-[`examples/basic/oauth_basic_agent`](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/basic/oauth_basic_agent) – an agent maintains persistent connections to the GitHub MCP server using the client-only loopback flow.
121
+
-[`examples/oauth/interactive_tool`](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/oauth/interactive_tool) – a client opens a temporary `gen_client` session, receives an `auth/request`, and walks through the browser login.
122
+
-[`examples/oauth/pre_authorize`](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/oauth/pre_authorize) – tokens are seeded before an asynchronous workflow runs so the background execution never needs interactive auth.
123
+
124
+
In each case, you get the same `ClientSession` interface; the difference lies in how tokens are acquired and stored.
125
+
126
+
## Initialisation hooks and authentication
127
+
128
+
You can register custom logic that runs immediately after a server initialises. It is perfect for seeding credentials, warming caches, or performing health checks.
When a server declares OAuth configuration (`mcp.servers[].auth.oauth`), `MCPApp` automatically injects an `OAuthHttpxAuth` handler so `MCPConnectionManager` can obtain and refresh tokens using the shared `TokenManager`. This means you do not need to ship long-lived access tokens in your config.
138
+
139
+
## Error handling & retries
15
140
16
-
-**MCP Server Registry** - Central registry of configured servers
17
-
-**MCP Connection Manager** - Lifecycle management for server connections
18
-
-**gen_client** - Context manager for temporary connections
-`MCPConnectionManager` keeps track of connection health and will surface errors via logs (`ProgressAction.FATAL_ERROR`) without crashing your application.
142
+
- Call `disconnect_all()` or `close()` if you want to force reconnection after rotating credentials.
143
+
- When a connection fails during initialisation, any awaiting `get_server` call unblocks with an exception so that workflows can decide whether to retry or degrade gracefully.
20
144
21
-
[See MCP Servers documentation for details →](/mcp-agent-sdk/core-components/mcp-servers)
145
+
[Deep dive into MCP Servers →](/mcp-agent-sdk/core-components/mcp-servers)
Copy file name to clipboardExpand all lines: docs/mcp-agent-sdk/core-components/execution-engine.mdx
+38-12Lines changed: 38 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,8 +47,9 @@ The Temporal engine provides durable workflow execution with automatic state per
47
47
```yaml
48
48
execution_engine: temporal
49
49
temporal:
50
-
server_url: "localhost:7233"
50
+
host: "localhost:7233"
51
51
namespace: "default"
52
+
task_queue: "mcp-agent"
52
53
```
53
54
54
55
**Use cases:**
@@ -58,6 +59,8 @@ temporal:
58
59
- Multi-node deployments
59
60
- Workflows requiring pause/resume
60
61
62
+
📌 **Example:** The [Temporal workflow gallery](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/temporal) showcases orchestrator, router, and evaluator/optimizer patterns running on this engine.
63
+
61
64
## Executors
62
65
63
66
Executors are the runtime components that actually execute workflows within an engine.
@@ -67,29 +70,38 @@ Executors are the runtime components that actually execute workflows within an e
67
70
Handles workflow execution for the asyncio engine:
68
71
69
72
```python
70
-
from mcp_agent.executors.asyncio_executor import AsyncioExecutor
73
+
from mcp_agent.executor.executor import AsyncioExecutor
74
+
75
+
async def greet(name: str) -> str:
76
+
return f"Hi {name}"
71
77
72
78
executor = AsyncioExecutor()
73
-
result = await executor.execute_workflow(workflow, params)
79
+
result = await executor.execute(greet, "Ada")
80
+
print(result) # "Hi Ada"
74
81
```
75
82
76
83
**Features:**
77
84
- Direct Python function execution
78
85
- Native async/await support
79
86
- Minimal overhead
80
87
88
+
See it in action in the [basic workflows examples](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/workflows) where tasks run entirely in-process.
89
+
81
90
### TemporalExecutor
82
91
83
92
Manages workflow execution for the Temporal engine:
84
93
85
94
```python
86
-
from mcp_agent.executors.temporal_executor import TemporalExecutor
87
-
88
-
executor = TemporalExecutor(
89
-
temporal_host="localhost:7233",
90
-
namespace="default"
91
-
)
92
-
result =await executor.execute_workflow(workflow, params)
95
+
from mcp_agent.executor.temporal import TemporalExecutor
@@ -98,6 +110,8 @@ result = await executor.execute_workflow(workflow, params)
98
110
- Distributed execution
99
111
- Workflow queries and signals
100
112
113
+
The [`examples/oauth/pre_authorize`](https://github.com/lastmile-ai/mcp-agent/tree/main/examples/oauth/pre_authorize) project combines this executor with OAuth-aware workflows.
114
+
101
115
## Choosing an Execution Engine
102
116
103
117
### Development Phase
@@ -200,15 +214,27 @@ logger:
200
214
```yaml
201
215
execution_engine: temporal
202
216
temporal:
203
-
server_url: "temporal.production.internal:7233"
217
+
host: "temporal.production.internal:7233"
204
218
namespace: "production"
205
219
task_queue: "agent-workflows"
206
220
worker_count: 4
207
221
max_concurrent_activities: 20
208
222
```
209
223
224
+
## Accessing the executor in an application
225
+
226
+
`MCPApp` exposes the active executor and engine selection:
227
+
228
+
```python
229
+
async with app.run() as running_app:
230
+
executor = running_app.executor
231
+
print(executor.execution_engine) # "asyncio" or "temporal"
232
+
```
233
+
234
+
You typically call high-level helpers (`workflow.execute()`, `executor.start_workflow`) rather than invoking executor methods directly, but the property is available when you need advanced control or diagnostics.
0 commit comments