summaryrefslogtreecommitdiff
path: root/integration-tests
diff options
context:
space:
mode:
authorJerop Kipruto <[email protected]>2025-06-18 18:53:58 -0400
committerGitHub <[email protected]>2025-06-18 15:53:58 -0700
commitb96fbd913e8449c99ed7b95920652acdce5dd779 (patch)
tree9b02b6dd6a0dd267101c564b88e0ae3d32330945 /integration-tests
parentcc89830b2ab74ec8d4a04e5846c7d3a08bb6d31b (diff)
test: add integration test for simple mcp server (#1199)
Diffstat (limited to 'integration-tests')
-rw-r--r--integration-tests/simple-mcp-server.test.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/integration-tests/simple-mcp-server.test.js b/integration-tests/simple-mcp-server.test.js
new file mode 100644
index 00000000..d585609e
--- /dev/null
+++ b/integration-tests/simple-mcp-server.test.js
@@ -0,0 +1,70 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import { test, describe, before, after } from 'node:test';
+import { strict as assert } from 'node:assert';
+import { TestRig } from './test-helper.js';
+import { spawn } from 'child_process';
+import { join } from 'path';
+import { fileURLToPath } from 'url';
+import { writeFileSync, unlinkSync } from 'fs';
+
+const __dirname = fileURLToPath(new URL('.', import.meta.url));
+const serverScriptPath = join(__dirname, './temp-server.js');
+
+const serverScript = `
+import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
+import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
+import { z } from 'zod';
+
+const server = new McpServer({
+ name: 'addition-server',
+ version: '1.0.0',
+});
+
+server.registerTool(
+ 'add',
+ {
+ title: 'Addition Tool',
+ description: 'Add two numbers',
+ inputSchema: { a: z.number(), b: z.number() },
+ },
+ async ({ a, b }) => ({
+ content: [{ type: 'text', text: String(a + b) }],
+ }),
+);
+
+const transport = new StdioServerTransport();
+await server.connect(transport);
+`;
+
+describe('simple-mcp-server', () => {
+ const rig = new TestRig();
+ let child;
+
+ before(() => {
+ writeFileSync(serverScriptPath, serverScript);
+ child = spawn('node', [serverScriptPath], {
+ stdio: ['pipe', 'pipe', 'pipe'],
+ });
+ child.stderr.on('data', (data) => {
+ console.error(`stderr: ${data}`);
+ });
+ // Wait for the server to be ready
+ return new Promise((resolve) => setTimeout(resolve, 500));
+ });
+
+ after(() => {
+ child.kill();
+ unlinkSync(serverScriptPath);
+ });
+
+ test('should add two numbers', () => {
+ rig.setup('should add two numbers');
+ const output = rig.run('add 5 and 10');
+ assert.ok(output.includes('15'));
+ });
+});