Skip to main content

Mojentic MCP is a module for the Mojentic framework that provides basic MCP server and client infrastructure for tools and chat agents.

Project description

Mojentic-MCP

Mojentic MCP is a library providing MCP (Machine Conversation Protocol) server and client infrastructure for tools and agentic chat creators. It allows you to easily expose tools to AI assistants that support the MCP protocol.

License: MIT Python 3.11+

🚀 Features

  • HTTP Transport: Expose the MCP protocol over HTTP using FastAPI
  • STDIO Transport: Expose the MCP protocol over standard input/output
  • JSON-RPC 2.0 Handler: Handle standard MCP requests and responses
  • Tool Integration: Easily expose custom tools to AI assistants
  • MCP Protocol Support: Implements the core MCP protocol methods. Currently, the primary focus is on the tools capabilities (tools/list, tools/call). Other methods like resources/list and prompts/list are stubbed to return empty lists for broader MCP compatibility.

🔧 Installation

pip install mojentic-mcp

🚦 Quick Start

HTTP Server Example

Create a simple HTTP MCP server with date-related tools:

import logging
import sys

logging.basicConfig(level=logging.INFO)

from mojentic.llm.tools.current_datetime import CurrentDateTimeTool
from mojentic.llm.tools.date_resolver import ResolveDateTool

from mojentic_mcp.mcp_http import HttpMcpServer
from mojentic_mcp.rpc import JsonRpcHandler

sys.stderr.write("Starting HTTP MCP server...\n")
sys.stderr.write("Server ready to receive commands\n")
rpc_handler = JsonRpcHandler(tools=[ResolveDateTool(), CurrentDateTimeTool()])
server = HttpMcpServer(rpc_handler)
server.run()

STDIO Server Example

Create a simple STDIO MCP server with date-related tools:

import logging
import sys

logging.basicConfig(level=logging.CRITICAL)

from mojentic.llm.tools.current_datetime import CurrentDateTimeTool
from mojentic.llm.tools.date_resolver import ResolveDateTool

from mojentic_mcp.mcp_stdio import StdioMcpServer
from mojentic_mcp.rpc import JsonRpcHandler

sys.stderr.write("Starting STDIO MCP server...\n")
sys.stderr.write("Server ready to receive commands on stdin\n")
rpc_handler = JsonRpcHandler(tools=[ResolveDateTool(), CurrentDateTimeTool()])
server = StdioMcpServer(rpc_handler)
server.run()

🛠️ Creating Custom Tools

You can create custom tools by extending the LLMTool class:

from mojentic.llm.tools.llm_tool import LLMTool
from mojentic_mcp.mcp_http import HttpMcpServer
from mojentic_mcp.rpc import JsonRpcHandler

class AboutTheUser(LLMTool):
    def run(self):
        return {
            "name": "Stacey",
            "favourite_colour": "purple"
        }

    @property
    def descriptor(self):
        return {
            "type": "function",
            "function": {
                "name": "colour_preferences",
                "description": "Return the user's favourite colour.",
                "parameters": {
                    "type": "object",
                    "properties": {},
                }
            }
        }

rpc_handler = JsonRpcHandler(tools=[AboutTheUser()])
server = HttpMcpServer(rpc_handler)
server.run()

📋 Task Management Example

Create a set of related tools that share state:

from mojentic.llm.tools.ephemeral_task_manager import EphemeralTaskList, AppendTaskTool, PrependTaskTool, \
    InsertTaskAfterTool, StartTaskTool, CompleteTaskTool, ListTasksTool, ClearTasksTool

from mojentic_mcp.mcp_http import HttpMcpServer
from mojentic_mcp.rpc import JsonRpcHandler

task_list = EphemeralTaskList()
rpc_handler = JsonRpcHandler(tools=[
    AppendTaskTool(task_list),
    PrependTaskTool(task_list),
    InsertTaskAfterTool(task_list),
    StartTaskTool(task_list),
    CompleteTaskTool(task_list),
    ListTasksTool(task_list),
    ClearTasksTool(task_list),
])
server = HttpMcpServer(rpc_handler)
server.run()

📚 MCP Protocol Reference

The library implements the following core JSON-RPC methods as specified by the MCP protocol. While methods for resources and prompts are present for MCP compatibility (returning empty lists), the current implementation is focused on delivering robust tools functionality.

Method Description
initialize Negotiates protocol version and capabilities
tools/list Lists available tools
tools/call Calls a tool with arguments
resources/list Lists available resources
prompts/list Lists available prompts

🔌 Client-Side API

The client-side API allows developers to easily interact with MCP servers. It supports multiple transports (HTTP, STDIO) and provides an idiomatic Python interface for tool discovery and invocation.

Initialization

from mojentic_mcp.client import McpClient
from mojentic_mcp.transports import HttpTransport, StdioTransport

# Define one or more transports
http_transport = HttpTransport(url="http://localhost:8080/jsonrpc")
stdio_transport = StdioTransport(command="/usr/local/bin/my_mcp_server_command")

# Initialize the client with a list of transports
client = McpClient(transports=[http_transport, stdio_transport])

Tool Invocation

Tools will be accessible as methods on a tools attribute of the client object:

# List available tools (aggregated from all transports)
tools_list = client.list_tools()

# Invoke a tool (client determines the correct transport)
resolved_date_result = client.tools.resolve_date(date_string="next Monday")
forecast_result = client.tools.get_weather_forecast(location="New York", days=3)

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mojentic_mcp-0.6.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mojentic_mcp-0.6.0-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file mojentic_mcp-0.6.0.tar.gz.

File metadata

  • Download URL: mojentic_mcp-0.6.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mojentic_mcp-0.6.0.tar.gz
Algorithm Hash digest
SHA256 aad265449a48af90aee1615b259e9b1ed5d700ebb14c49436e17bc84c44793b2
MD5 ce1d9acf0c82fc77a41a2bdd7774029e
BLAKE2b-256 1357c5a717a97f7344a080288403e8432eeece663348e460f9b4ebd65e1c1f08

See more details on using hashes here.

Provenance

The following attestation bundles were made for mojentic_mcp-0.6.0.tar.gz:

Publisher: python-publish.yml on svetzal/mojentic-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mojentic_mcp-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: mojentic_mcp-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mojentic_mcp-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 424ab10439a4b97285fd60bf3786a96151a85ac26e347e2ffcafacf216eabe72
MD5 eccd93b632f0277b8c902b2650426f0c
BLAKE2b-256 f897d7875aaafb2deb119bcc3d8626cd35872b6790855e34710f05365cddb234

See more details on using hashes here.

Provenance

The following attestation bundles were made for mojentic_mcp-0.6.0-py3-none-any.whl:

Publisher: python-publish.yml on svetzal/mojentic-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page