mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
feat(test-utils): add TestMcpServerBuilder and support in TestRig (#23491)
This commit is contained in:
@@ -10,6 +10,58 @@ published to npm.
|
||||
- `src/file-system-test-helpers.ts`: Helpers for creating temporary file system
|
||||
fixtures.
|
||||
- `src/mock-utils.ts`: Common mock utilities.
|
||||
- `src/test-mcp-server.ts`: Helper for building test MCP servers for tests.
|
||||
- `src/test-mcp-server-template.mjs`: Generic template script for running
|
||||
isolated MCP processes.
|
||||
|
||||
## Test MCP Servers
|
||||
|
||||
The `TestRig` provides a fully isolated, compliant way to test tool triggers and
|
||||
workflows using local test MCP servers. This isolates your tests from live API
|
||||
endpoints and rate-limiting.
|
||||
|
||||
### Usage
|
||||
|
||||
1. **Programmatic Builder:**
|
||||
|
||||
```typescript
|
||||
import { TestMcpServerBuilder } from '@google/gemini-cli-test-utils';
|
||||
|
||||
const builder = new TestMcpServerBuilder('weather-server').addTool(
|
||||
'get_weather',
|
||||
'Get weather',
|
||||
'It is rainy',
|
||||
);
|
||||
|
||||
rig.addTestMcpServer('weather-server', builder.build());
|
||||
```
|
||||
|
||||
2. **Predefined configurations via JSON:** Place a configuration file in
|
||||
`packages/test-utils/assets/test-servers/google-workspace.json` and load it
|
||||
by title:
|
||||
|
||||
```typescript
|
||||
rig.addTestMcpServer('workspace-server', 'google-workspace');
|
||||
```
|
||||
|
||||
**JSON Format Structure (`TestMcpConfig`):**
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "string (Fallback server name)",
|
||||
"tools": [
|
||||
{
|
||||
"name": "string (Tool execution name)",
|
||||
"description": "string (Helpful summary for router)",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": { ... }
|
||||
},
|
||||
"response": "string | object (The forced reply payload)"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
||||
Reference in New Issue
Block a user