Skip to content

Conversation

samchon
Copy link
Owner

@samchon samchon commented Apr 21, 2025

Support validation feedback and LLM model specification for MCP.


This pull request introduces a significant update to the @samchon/openapi package, focusing on adding support for MCP (Model Context Protocol) integration and enhancing the LLM (Large Language Model) function-calling capabilities. Key changes include the addition of the McpLlm namespace, new structures for MCP-based function handling, and updates to OpenAPI V3.1 schema conversion utilities. These changes aim to improve schema validation, function composition, and error handling for LLM applications.

MCP Integration and LLM Enhancements:

  • Added the McpLlm namespace in src/McpLlm.ts, which includes a new application function for converting MCP documents into LLM function-calling applications. This includes support for schema validation, error handling, and context reduction strategies.
  • Introduced new interfaces: IMcpLlmApplication, IMcpLlmFunction, and IMcpTool, which define the structure and metadata for MCP-based LLM functions and tools. These interfaces support validation and error reporting during function composition. [1] [2] [3]
  • Updated src/index.ts to export the newly added MCP-related namespaces and structures.

OpenAPI V3.1 Schema Conversion Improvements:

  • Exported convertComponents and convertSchema functions in OpenApiV3_1Emender to enable external usage for schema conversion. [1] [2]
  • Enhanced schema conversion logic to handle $ref and $recursiveRef attributes more robustly, ensuring proper resolution of references in OpenAPI schemas. [1] [2]

Documentation and Test Additions:

  • Added detailed JSDoc comments to the new MCP-related namespaces and interfaces, explaining their purpose, usage, and benefits. [1] [2] [3]
  • Introduced a new test case, test_mcp_schema_ref, to validate MCP schema references and ensure compatibility with LLM function calling.

Miscellaneous Updates:

  • Updated package.json version from 4.1.0 to 4.2.0 to reflect the new features and improvements.
  • Simplified parameter descriptions in the HttpLlm namespace to align with the new MCP-based approach.

These updates collectively enhance the package's ability to handle MCP documents and improve the reliability of LLM function-calling workflows.

Support validation feedback and model specification for MCP.
@samchon samchon added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 21, 2025
@samchon samchon requested a review from Copilot April 21, 2025 08:39
@samchon samchon self-assigned this Apr 21, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for the Model Context Protocol (MCP) and enhances LLM function-calling capabilities in the @samchon/openapi package by introducing new namespaces, interfaces, and updated schema conversion logic.

  • Added the McpLlm namespace and new interfaces to handle MCP-based tools and functions.
  • Improved OpenAPI V3.1 schema conversion to correctly resolve references.
  • Included new test cases for validating MCP application behavior and schema references.

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/src/features/mcp/validate_mcp_application.ts Added tests for validating MCP applications with various models.
test/src/features/mcp/test_mcp_schema_ref.ts Introduced schema reference testing to ensure proper filtering and resolution.
src/structures/IMcpTool.ts Defined the IMcpTool interface for MCP tools with associated schema definitions.
src/structures/IMcpLlmFunction.ts Added MCP LLM function interface with validation features.
src/structures/IMcpLlmApplication.ts Defined the MCP LLM application interface for aggregating functions and errors.
src/ILlmFunction.ts Updated ILlmFunction interface to include separated parameters.
src/index.ts Exported new MCP and related interfaces for external usage.
src/converters/OpenApiV3_1Emender.ts Revised schema conversion functions to standardize $ref resolution.
src/McpLlm.ts Implemented the MCP to LLM application conversion with error handling.
src/HttpLlm.ts Updated documentation to reflect the new MCP-based composition approach.
Files not reviewed (1)
  • package.json: Language not supported
Comments suppressed due to low confidence (2)

src/structures/IMcpTool.ts:47

  • The term 'restict' appears to be a spelling error; please change it to 'restrict'.
 * As MCP (Model Context Protocol) does not restict the JSON schema specification, `@samchon/openapi` has defined it to be universal

src/structures/IMcpLlmApplication.ts:22

  • There is a spelling mistake in 'functi0on'; it should be 'function'.
 * each function has its own {@link IMcpLlmFunction.validate} functi0on for correcting AI agent's mistakes, and this is the reason why

src/McpLlm.ts Outdated
[key, (props.options as any)?.[key] ?? value] as const,
),
),
maxLength: props.options?.maxLength ?? null,
Copy link
Preview

Copilot AI Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default for maxLength is set to null, but according to the IOptions type it should be a number; consider using a numeric default such as 64.

Suggested change
maxLength: props.options?.maxLength ?? null,
maxLength: props.options?.maxLength ?? 64,

Copilot uses AI. Check for mistakes.

@samchon samchon requested a review from Copilot April 21, 2025 08:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for MCP (Model Context Protocol) integration and enhances LLM function-calling capabilities in the @samchon/openapi package. It introduces new MCP namespaces and interfaces, updates OpenAPI V3.1 schema conversion utilities, and supplements the package with additional test cases to validate the new MCP functionalities.

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/src/features/mcp/validate_mcp_application.ts Adds tests to validate MCP applications for various models.
test/src/features/mcp/test_mcp_schema_ref.ts Introduces a test case to verify schema reference filtering in MCP.
src/structures/IMcpTool.ts Defines the interface for MCP tools.
src/structures/IMcpLlmFunction.ts Adds type definitions for MCP LLM functions.
src/structures/IMcpLlmApplication.ts Defines the application interface for MCP-based LLM functions.
src/structures/ILlmFunction.ts Enhances ILlmFunction interface with separated parameter support.
src/index.ts Exports the new MCP namespaces and structures.
src/converters/OpenApiV3_1Emender.ts Updates schema conversion functions for OpenAPI components and refs.
src/McpLlm.ts Implements MCP-to-LLM application conversion with validation support.
src/HttpLlm.ts Adjusts HTTP LLM application composition by enforcing a default maxLength.
Files not reviewed (1)
  • package.json: Language not supported

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@samchon samchon merged commit 1b84e59 into master Apr 21, 2025
4 checks passed
@samchon samchon deleted the feat/mcp branch April 21, 2025 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant