Skip to content

Replace any types with proper interfaces in test utilities#24

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/define-sse-response-interface
Draft

Replace any types with proper interfaces in test utilities#24
Copilot wants to merge 6 commits intomainfrom
copilot/define-sse-response-interface

Conversation

Copy link

Copilot AI commented Feb 12, 2026

Test utilities used any types throughout, reducing type safety and making response structures unclear to consumers.

Changes

Response Type Definitions

  • Added SSEResponseData type for SSE response parsing
  • Added McpToolResponse interfaces for JSON-RPC 2.0 tool call responses
  • Added ListMcpToolsResponse interfaces for JSON-RPC 2.0 tool listing
  • All id fields typed as number | string | null per JSON-RPC 2.0 spec

Function Signatures

  • parseSSEResponse: Return type anySSEResponseData
  • callMCPTool: Parameter args: anyargs: unknown, return type Promise<any>Promise<McpToolResponse | SSEResponseData>
  • listMCPTools: Return type Promise<any>Promise<ListMcpToolsResponse | ListMcpToolsSseResponse>

Test Reliability

  • Replaced Math.random() with deterministic counter for JSON-RPC IDs
  • Exported resetJsonRpcId() for test isolation

Example

Before:

export function parseSSEResponse(sseText: string): any { ... }
export async function callMCPTool(baseUrl: string, sessionId: string, toolName: string, args: any): Promise<any> { ... }

After:

export type SSEResponseData = Record<string, unknown>;
export function parseSSEResponse(sseText: string): SSEResponseData { ... }

interface McpToolResponse { jsonrpc: "2.0"; id: number | string | null; result?: unknown; error?: {...}; }
export async function callMCPTool(baseUrl: string, sessionId: string, toolName: string, args: unknown): Promise<McpToolResponse | SSEResponseData> { ... }
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"Function returns 'any' type which makes it difficult for consumers to understand what structure to expect. Consider defining a proper interface for the SSE response structure.","fixFiles":[{"filePath":"test/test-utils.ts","diff":"diff --git a/test/test-utils.ts b/test/test-utils.ts\n--- a/test/test-utils.ts\n+++ b/test/test-utils.ts\n@@ -41,7 +41,9 @@\n /**\n  * Parse SSE (Server-Sent Events) response\n  */\n-export function parseSSEResponse(sseText: string): any {\n+export type SSEResponseData = Record<string, unknown>;\n+\n+export function parseSSEResponse(sseText: string): SSEResponseData {\n   const lines = sseText.trim().split(\"\\n\");\n   for (const line of lines) {\n     if (line.startsWith(\"data: \")) {\n"}]},{"message":"Parameter 'args' uses 'any' type which reduces type safety. Consider using a more specific type or generic constraint.","fixFiles":[{"filePath":"test/test-utils.ts","diff":"diff --git a/test/test-utils.ts b/test/test-utils.ts\n--- a/test/test-utils.ts\n+++ b/test/test-utils.ts\n@@ -165,7 +165,7 @@\n   baseUrl: string,\n   sessionId: string,\n   toolName: string,\n-  args: any\n+  args: unknown\n ): Promise<any> {\n   const response = await fetch(baseUrl, {\n     method: \"POST\",\n"}]},{"message":"Function returns 'any' type which makes it difficult for consumers to understand what structure to expect. Consider defining a proper interface for the MCP tool response.","fixFiles":[{"filePath":"test/test-utils.ts","diff":"diff --git a/test/test-utils.ts b/test/test-utils.ts\n--- a/test/test-utils.ts\n+++ b/test/test-utils.ts\n@@ -159,6 +159,29 @@\n }\n \n /**\n+ * JSON-RPC response types for MCP tool calls\n+ */\n+interface McpToolError {\n+  code: number;\n+  message: string;\n+  data?: unknown;\n+}\n+\n+interface McpToolSuccessResult {\n+  jsonrpc: \"2.0\";\n+  id: number;\n+  result: unknown;\n+}\n+\n+interface McpToolErrorResult {\n+  jsonrpc: \"2.0\";\n+  id: number | null;\n+  error: McpToolError;\n+}\n+\n+type McpToolResponse = McpToolSuccessResult | McpToolErrorResult;\n+\n+/**\n  * Call MCP tool\n  */\n export async function callMCPTool(\n@@ -166,7 +189,7 @@\n   sessionId: string,\n   toolName: string,\n   args: any\n-): Promise<any> {\n+): Promise<unknown | McpToolResponse> {\n   const response = await fetch(baseUrl, {\n     method: \"POST\",\n     headers: {\n@@ -195,17 +218,42 @@\n     const text = await response.text();\n     return parseSSEResponse(text);\n   } else {\n-    return response.json();\n+    return response.json() as Promise<McpToolResponse>;\n   }\n }\n \n /**\n+ * JSON-RPC response types for listing MCP tools\n+ */\n+interface McpToolDescription {\n+  name: string;\n+  description?: string;\n+  inputSchema?: unknown;\n+}\n+\n+interface McpListToolsResult {\n+  jsonrpc: \"2.0\";\n+  id: number;\n+  result: {\n+    tools: McpToolDescription[];\n+  };\n+}\n+\n+interface McpListToolsErrorResult {\n+  jsonrpc: \"2.0\";\n+  id: number | null;\n+  error: McpToolError;\n+}\n+\n+type McpListToolsResponse = McpListToolsResult | McpListToolsErrorResult;\n+\n+/**\n  * List MCP tools\n  */\n export async function listMCPTools(\n   baseUrl: string,\n   sessionId: string\n-): Promise<any> {\n+): Promise<unknown | McpListToolsResponse> {\n   const response = await fetch(baseUrl, {\n     method: \"POST\",\n     headers: {\n@@ -230,6 +269,6 @@\n     const text = await response.text();\n     return parseSSEResponse(text);\n   } else {\n-    return response.json();\n+    return response.json() as Promise<McpListToolsResponse>;\n   }\n }\n"}]},{"message":"Function returns 'any' type which makes it difficult for consumers to understand what structure to expect. Consider defining a proper interface for the MCP tools list response.","fixFiles":[{"filePath":"test/test-utils.ts","diff":"diff --git a/test/test-utils.ts b/test/test-utils.ts\n--- a/test/test-utils.ts\n+++ b/test/test-utils.ts\n@@ -1,6 +1,43 @@\n import { spawn, ChildProcess } from \"child_process\";\n \n /**\n+ * A single MCP tool description returned by the tools/list method.\n+ * This is a minimal structural type to avoid using `any` while allowing\n+ * the response to include additional properties.\n+ */\n+export interface McpToolDescription {\n+  name: string;\n+  description?: string;\n+  // Allow additional properties without losing type safety.\n+  [key: string]: unknown;\n+}\n+\n+/**\n+ * JSON-RPC 2.0 response for the tools/list method,\n+ * when returned as a standard JSON HTTP response.\n+ */\n+export interface ListMcpToolsResponse {\n+  jsonrpc: \"2.0\";\n+  id: number | string | null;\n+  result?: {\n+    tools?: McpToolDescription[];\n+    [key: string]: unknown;\n+  };\n+  error?: {\n+    code: number;\n+    message: string;\n+    data?: unknown;\n+  };\n+}\n+\n+/**\n+ * Response shape when the tools/list call is delivered via\n+ ...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits February 12, 2026 16:17
…r interfaces

Co-authored-by: maxgolov <34072974+maxgolov@users.noreply.github.com>
…ype assertions

Co-authored-by: maxgolov <34072974+maxgolov@users.noreply.github.com>
…response type

Co-authored-by: maxgolov <34072974+maxgolov@users.noreply.github.com>
Co-authored-by: maxgolov <34072974+maxgolov@users.noreply.github.com>
….0 spec

Co-authored-by: maxgolov <34072974+maxgolov@users.noreply.github.com>
Copilot AI changed the title [WIP] Update SSE response function to use defined interface Replace any types with proper interfaces in test utilities Feb 12, 2026
Copilot AI requested a review from maxgolov February 12, 2026 16:24
@github-actions
Copy link

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments