Skip to content

Commit e272eb7

Browse files
committed
Implement Centralized Logger for MCP Servers #7534
1 parent e477a8c commit e272eb7

4 files changed

Lines changed: 43 additions & 3 deletions

File tree

.github/ISSUE/ticket-mcp-server-logging.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ title: Implement Centralized Logger for MCP Servers
33
labels: enhancement, AI
44
---
55

6-
GH ticket id: #(TBD)
6+
GH ticket id: #7534
77

8-
**Epic:** Architect AI Tooling as MCP
98
**Assignee:** tobiu
109
**Status:** Done
1110

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Enhance MCP ToolService to Support OpenAPI Keywords
3+
labels: enhancement, AI
4+
---
5+
6+
GH ticket id: #7535
7+
8+
**Assignee:** tobiu
9+
**Status:** Done
10+
11+
## Description
12+
13+
The `ai/mcp/server/toolService.mjs` is responsible for parsing OpenAPI specifications and generating Zod schemas for validating tool inputs and outputs. The current implementation of `buildZodSchemaFromResponse` is too simplistic and does not support common OpenAPI keywords like `oneOf`, `required`, and `nullable`. This leads to schema validation errors when the OpenAPI spec uses these features.
14+
15+
This ticket is to enhance the `buildZodSchemaFromResponse` function to correctly handle these keywords, making the tool service more robust and compliant with the OpenAPI specification.
16+
17+
## Acceptance Criteria
18+
19+
1. The `buildZodSchemaFromResponse` function in `ai/mcp/server/toolService.mjs` is updated to handle the `oneOf` keyword by mapping it to Zod's `z.union`.
20+
2. The function is updated to handle the `required` keyword for object properties, making properties optional in the Zod schema if they are not in the `required` list.
21+
3. The function is updated to handle `nullable: true` by applying `.nullable()` to the Zod schema.
22+
4. The `openapi.yaml` for the memory-core server is simplified to use `nullable: true` for the `pid` property, removing the need for complex `oneOf` constructs.
23+
5. The `neo-memory-core__healthcheck` tool passes successfully with these changes.

ai/mcp/server/memory-core/openapi.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,11 @@ components:
503503
example: true
504504
pid:
505505
type: integer
506+
nullable: true
506507
example: 12345
508+
managed:
509+
type: boolean
510+
example: true
507511
connection:
508512
type: object
509513
properties:

ai/mcp/server/toolService.mjs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,22 @@ function buildZodSchemaFromResponse(doc, schema) {
106106
return buildZodSchemaFromResponse(doc, resolveRef(doc, schema.$ref));
107107
}
108108

109+
if (schema.oneOf) {
110+
const options = schema.oneOf.map(s => buildZodSchemaFromResponse(doc, s));
111+
return z.union(options);
112+
}
113+
109114
let zodSchema;
110115
if (schema.type === 'object') {
111116
const shape = {};
112117
if (schema.properties) {
118+
const required = schema.required || [];
113119
for (const [propName, propSchema] of Object.entries(schema.properties)) {
114-
shape[propName] = buildZodSchemaFromResponse(doc, propSchema);
120+
let propertySchema = buildZodSchemaFromResponse(doc, propSchema);
121+
if (!required.includes(propName)) {
122+
propertySchema = propertySchema.optional();
123+
}
124+
shape[propName] = propertySchema;
115125
}
116126
}
117127
zodSchema = z.object(shape);
@@ -127,6 +137,10 @@ function buildZodSchemaFromResponse(doc, schema) {
127137
zodSchema = z.any();
128138
}
129139

140+
if (schema.nullable) {
141+
zodSchema = zodSchema.nullable();
142+
}
143+
130144
if (schema.description) {
131145
zodSchema = zodSchema.describe(schema.description);
132146
}

0 commit comments

Comments
 (0)