[PR #105] [MERGED] feat: support cusotm BaseModel "$def" and Output schema #162

Closed
opened 2026-02-15 21:15:10 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/mcpo/pull/105
Author: @JinY0ung-Shin
Created: 4/28/2025
Status: Merged
Merged: 4/30/2025
Merged by: @tjbck

Base: devHead: main


📝 Commits (5)

  • 4ad458f Merge pull request #75 from open-webui/dev
  • e392df0 Support Custom basemode and output schema
  • 464d886 Support Custom basemode and output schema
  • 6f04974 Merge branch 'dev' into main
  • 780dd93 Merge branch 'dev' into main

📊 Changes

2 files changed (+64 additions, -24 deletions)

View changed files

📝 src/mcpo/main.py (+25 -13)
📝 src/mcpo/utils/main.py (+39 -11)

📄 Description

Pull Request Checklist

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests to validate the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To clearly categorize this pull request, prefix the pull request title using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

  • Add Custom BaseModel Support which returns "$defs" filed in json schema. For example
from pydantic import BaseModel
from typing import List
class User(BaseModel):
    name: str
    age: int

class UserList(BaseModel):
    users: List[User]

if __name__ == "__main__":
    print(UserList.model_json_schema())

>>>{'$defs': {'User': {'properties': {'name': {'title': 'Name', 'type': 'string'}, 'age': {'title': 'Age', 'type': 'integer'}}, 'required': ['name', 'age'], 'title': 'User', 'type': 'object'}}, 'properties': {'users': {'items': {'$ref': '#/$defs/User'}, 'title': 'Users', 'type': 'array'}}, 'required': ['users'], 'title': 'UserList', 'type': 'object'}
  • Add output shcema which enable user to define output schema for the tool. LLM can use this schema to validate the output of the tool. For example
class ToolRegistry:
    def __init__(self):
        self._tools: Dict[str, Type[BaseTool]] = {}
        self._input_schemas: Dict[str, BaseModel] = {}

    def register(self, name: str, description: str):
        def decorator(tool_cls: Type[BaseTool]):
            self._tools[name] = tool_cls
            self._input_schemas[name] = tool_cls.InputSchema
            tool_cls.name = name
            tool_cls.description = description
            return tool_cls

        return decorator

    def get_tool_instances(self):
        return {name: tool_cls() for name, tool_cls in self._tools.items()}

    def get_mcp_tools(self):
        return [
            Tool(
                name=name,
                description=tool_cls.description,
                inputSchema=tool_cls.InputSchema.model_json_schema(),
                outputSchema=tool_cls.OutputSchema.model_json_schema(),
            )
            for name, tool_cls in self._tools.items()
        ]

It automatically register to FastAPI documentation.

Added

  • Custom BaseModel Support
  • OutputSchema Support


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/mcpo/pull/105 **Author:** [@JinY0ung-Shin](https://github.com/JinY0ung-Shin) **Created:** 4/28/2025 **Status:** ✅ Merged **Merged:** 4/30/2025 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `main` --- ### 📝 Commits (5) - [`4ad458f`](https://github.com/open-webui/mcpo/commit/4ad458f8680979a5286492f3c0b4ed4f73e2f4b2) Merge pull request #75 from open-webui/dev - [`e392df0`](https://github.com/open-webui/mcpo/commit/e392df07634735d16627af4a035cbfca81b487bb) Support Custom basemode and output schema - [`464d886`](https://github.com/open-webui/mcpo/commit/464d8866735047b4d2e8a44cdf875881e47477ed) Support Custom basemode and output schema - [`6f04974`](https://github.com/open-webui/mcpo/commit/6f04974d5dad0a9006e9a0946c2c7466dd407ede) Merge branch 'dev' into main - [`780dd93`](https://github.com/open-webui/mcpo/commit/780dd930806f34fd95eb0eca58c02fbdf206aa70) Merge branch 'dev' into main ### 📊 Changes **2 files changed** (+64 additions, -24 deletions) <details> <summary>View changed files</summary> 📝 `src/mcpo/main.py` (+25 -13) 📝 `src/mcpo/utils/main.py` (+39 -11) </details> ### 📄 Description # Pull Request Checklist **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests to validate the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To clearly categorize this pull request, prefix the pull request title using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description - Add Custom BaseModel Support which returns "$defs" filed in json schema. For example ```python from pydantic import BaseModel from typing import List class User(BaseModel): name: str age: int class UserList(BaseModel): users: List[User] if __name__ == "__main__": print(UserList.model_json_schema()) >>>{'$defs': {'User': {'properties': {'name': {'title': 'Name', 'type': 'string'}, 'age': {'title': 'Age', 'type': 'integer'}}, 'required': ['name', 'age'], 'title': 'User', 'type': 'object'}}, 'properties': {'users': {'items': {'$ref': '#/$defs/User'}, 'title': 'Users', 'type': 'array'}}, 'required': ['users'], 'title': 'UserList', 'type': 'object'} ``` - Add output shcema which enable user to define output schema for the tool. LLM can use this schema to validate the output of the tool. For example ```python class ToolRegistry: def __init__(self): self._tools: Dict[str, Type[BaseTool]] = {} self._input_schemas: Dict[str, BaseModel] = {} def register(self, name: str, description: str): def decorator(tool_cls: Type[BaseTool]): self._tools[name] = tool_cls self._input_schemas[name] = tool_cls.InputSchema tool_cls.name = name tool_cls.description = description return tool_cls return decorator def get_tool_instances(self): return {name: tool_cls() for name, tool_cls in self._tools.items()} def get_mcp_tools(self): return [ Tool( name=name, description=tool_cls.description, inputSchema=tool_cls.InputSchema.model_json_schema(), outputSchema=tool_cls.OutputSchema.model_json_schema(), ) for name, tool_cls in self._tools.items() ] ``` It automatically register to FastAPI documentation. ### Added - Custom BaseModel Support - OutputSchema Support --- --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 21:15:10 -05:00
yindo closed this issue 2026-02-15 21:15:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: open-webui/mcpo#162