litemcp

mcp
Guvenlik Denetimi
Uyari
Health Uyari
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 6 GitHub stars
Code Gecti
  • Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Gecti
  • Permissions — No dangerous permissions requested

Bu listing icin henuz AI raporu yok.

SUMMARY

A minimal, lightweight client designed to simplify SDK adoption into MCP

README.md

✨ litemcp

A minimal, lightweight client designed to simplify SDK adoption into MCP.

litemcp enables rapid and intuitive integration of various AI SDKs (e.g., LangChain, Agent SDK) into your MCP projects, emphasizing simplicity, flexibility, and minimal dependencies.

🌟 Key Features

  • Simplicity: Streamlined interfaces ensure easy integration.
  • Flexibility: Quickly adopt diverse SDKs with minimal effort.
  • Lightweight: Designed with minimal dependencies to maximize clarity and performance.

🛠 Installation

Install via pip:

pip install litemcp

🚀 Quick Start

litemcp allows you to integrate tools from an MCP server into various LLM runtimes, including the OpenAI Agent SDK, LangChain, and direct OpenAI API calls.

Tool discovery is shared by concurrent callers and cached for each async with MCPServerManager(...) block. Open a new block to refresh the tool list. You can run tool calls concurrently inside that block, but await them all before leaving it (for example, use asyncio.TaskGroup). Do not enter the same manager instance twice at the same time.

Below are three examples showing how to use litemcp in different contexts:

✅ OpenAI Agent SDK Integration

async def main():
    async with MCPServerManager(sys.argv[1]) as server_manager:
        mcp_server_tools = await server_manager.agent_sdk_tools()

        agent = Agent(
            name="assistant",
            instructions="You are an AI assistant.",
            tools=mcp_server_tools,
        )

        result = await Runner.run(agent, "List all the kubernetes clusters")
        print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

✅ LangChain Integration

async def main(config):
    chat = ChatOpenAI(model="gpt-3.5-turbo-0125")
    async with MCPServerManager(config) as server_manager:

        # bind tools
        tools: List[BaseTool] = await server_manager.langchain_tools()
        chat_with_tools = chat.bind_tools(tools, tool_choice="any")

        messages = [
            SystemMessage(content="You're a helpful assistant"),
            HumanMessage(content="List the dirs in the /Users"),
        ]
        tool_calls = (await chat_with_tools.ainvoke(messages)).tool_calls

        # invoke the tool_call
        tool_map = {tool.name: tool for tool in tools}
        for tool_call in tool_calls:
            selected_tool = tool_map[tool_call["name"]]
            tool_output = await selected_tool.ainvoke(tool_call["args"])
            print(tool_output)

✅ Direct OpenAI API Integration

async def main(config):
    client = AsyncOpenAI()

    async with client, MCPServerManager(config) as server_manager:
        schemas = await server_manager.schemas()

        completion = await client.chat.completions.create(
            model="gpt-4o",
            messages=[{"role": "user", "content": "List the dirs in the /Users"}],
            tools=schemas,
        )

        for tool_call in completion.choices[0].message.tool_calls or []:
            result = await server_manager.tool_call(
                tool_call.function.name, tool_call.function.arguments
            )
            if isinstance(result, str):
                print(result)  # The validator denied the call.
            elif result is not None:
                print(result.content)

🔐 Tool Call Validator(Optional)

Use register_validator to validate tool arguments or require approval before a call. To enforce approval, list the tool in its server's requires_confirmation setting: the manager will block it if no validator is registered. A registered validator must return None or an empty string to allow the call, or a non-empty message to deny it. This applies to the OpenAI Agents SDK, LangChain, and direct calls through tool_call.

1. Define the Validator

def applier_validator(func_args) -> str | None:
    answer = input("Proceed with this YAML? (yes/no): ").strip().lower()
    if answer in {"yes", "y"}:
        return None
    return "Tool call denied: approval was not given."

2. Register the Validator with MCP Server

async with MCPServerManager(sys.argv[1]) as server_manager:
    server_manager.register_validator("yaml_applier", applier_validator)

    mcp_server_tools = await server_manager.agent_sdk_tools()

    engineer = Agent(...)

📖 MCP Configuration Schema

Each MCP server uses one of two transports: set command (with optional args and env) for a local stdio process, or set url to the SSE endpoint of a running MCP server. Do not set both. The same configuration can contain both kinds of servers.

{
  "mcpServers": {
    "puppeteer": {
      "url": "http://127.0.0.1:8000/sse"
    },
    "fetch": {
      "command": "uvx",
      "args": ["mcp-server-fetch"]
    },
    "youtube": {
      "command": "npx",
      "args": ["-y", "github:anaisbetts/mcp-youtube"],
      "exclude_tools": ["..."]
    },
    "mcp-server-commands": {
      "command": "npx",
      "args": ["mcp-server-commands"],
      "requires_confirmation": [
        "run_command",
        "run_script"
      ],
      "enabled": false
    },
     "multicluster-mcp-server": {
      "command": "node",
      "args": [".../multicluster-mcp-server/build/index.js"],
      "enabled": false
    }
  }
}
  • Use "enabled": true/false to activate or deactivate servers.
  • Use "exclude_tools" to omit tools from a server. Exposed tool names must be unique across enabled, selected servers; exclude duplicates to avoid ambiguous routing.
  • Stdio processes inherit only the MCP SDK's default environment, not the client's full environment. Explicitly supply any extra variables a trusted server needs via "env".
  • A url must point to an MCP SSE endpoint, not a Streamable HTTP endpoint. Only connect to servers you trust.

📖 Documentation

Detailed documentation coming soon!

📢 Contributing

Contributions and suggestions are welcome! Please open an issue or submit a pull request.

📜 License

liteMCP is available under the MIT License.

Yorumlar (0)

Sonuc bulunamadi