AI工具本地库

一个无需运行MCP服务器即可在本地使用AI工具库的轻量级解决方案。

  • by fomenko-ai
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 fomenko-ai/mcp-lite

使用说明

mcp-lite

用于在不运行MCP服务器的情况下使用AI工具进行本地工作的库。

安装

uv add mcp-lite

导入

from mcp_lite import MCP

用法

from typing import List

from mcp_lite import MCP, Tool


mcp = MCP()


@mcp.tool
def sync_add(a, b):
    """
    Call this function if you need to add two numbers.

    Args:
        a (int | float): The first number.
        b (int | float): The second number.
    """
    return a + b


@mcp.tool
async def async_mul(a, b):
    """
    Call this function if you need to multiply two numbers.

    Args:
        a (int | float): The first number.
        b (int | float): The second number.
    """
    return a * b


tools: List[Tool] = mcp.list_tools()

tools_description = "\n".join(
    f"- {tool.name}: {tool.description}" 
    for tool in tools
)

# Some code where AI calls some tools :)

for tool_call in tool_calls:
    tool_name = tool_call.get("tool_name")
    tool_args = tool_call.get("args", {})

    tool_result = await mcp.call_tool(tool_name, tool_args)