include the in=query parameters in the inputSchema

When a parameter has `in` = `query`, it means the value is passed as an HTTP parameter in the
URL of the query.

e.g:

```
"parameters": [
  {
    "description": "A search term.",
    "in": "query",
    "name": "search",
    "required": false,
    "type": "string"
  },
(...)
```
This commit is contained in:
Gonéri Le Bouder 2025-09-25 16:19:14 -04:00
parent f29c277860
commit 960a3b38aa
No known key found for this signature in database

View File

@ -7,6 +7,16 @@ import { generateOperationId } from '../utils/code-gen.js';
import { McpToolDefinition } from '../types/index.js'; import { McpToolDefinition } from '../types/index.js';
import { shouldIncludeOperationForMcp } from '../utils/helpers.js'; import { shouldIncludeOperationForMcp } from '../utils/helpers.js';
export interface ParameterObjectWithType extends OpenAPIV3.ParameterObject {
name: string;
description?: string;
in: string;
type?: JSONSchema7TypeName;
required?: boolean;
schema?: OpenAPIV3.SchemaObject;
}
/** /**
* Extracts tool definitions from an OpenAPI document * Extracts tool definitions from an OpenAPI document
* *
@ -124,8 +134,8 @@ export function generateInputSchemaAndDetails(operation: OpenAPIV3.OperationObje
const required: string[] = []; const required: string[] = [];
// Process parameters // Process parameters
const allParameters: OpenAPIV3.ParameterObject[] = Array.isArray(operation.parameters) const allParameters: ParameterObjectWithType[] = Array.isArray(operation.parameters)
? operation.parameters.map((p) => p as OpenAPIV3.ParameterObject) ? operation.parameters.map((p) => p as ParameterObjectWithType)
: []; : [];
allParameters.forEach((param) => { allParameters.forEach((param) => {
@ -174,6 +184,16 @@ export function generateInputSchemaAndDetails(operation: OpenAPIV3.OperationObje
} }
} }
allParameters.forEach((item) => {
if (properties[item.name]) return;
properties[item.name] = {
description: item.description,
type: item.type ?? item.schema?.type,
};
if (item.required) required.push(item.name);
});
// Combine everything into a JSON Schema // Combine everything into a JSON Schema
const inputSchema: JSONSchema7 = { const inputSchema: JSONSchema7 = {
type: 'object', type: 'object',