https://github.com/marios-mamalis/pythonlibrary2mcp
Quickly expose existing Python library functions as MCP server tools
https://github.com/marios-mamalis/pythonlibrary2mcp
automation fastmcp model-context-protocol model-context-protocol-servers python-library
Last synced: 3 months ago
JSON representation
Quickly expose existing Python library functions as MCP server tools
- Host: GitHub
- URL: https://github.com/marios-mamalis/pythonlibrary2mcp
- Owner: Marios-Mamalis
- License: apache-2.0
- Created: 2025-06-19T19:10:04.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-07-11T16:55:14.000Z (6 months ago)
- Last Synced: 2025-07-11T18:42:54.179Z (6 months ago)
- Topics: automation, fastmcp, model-context-protocol, model-context-protocol-servers, python-library
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PythonLibrary2MCP



The purpose of this utility is to provide a simple way to quickly port functions of existing Python
libraries (both built-in and external) as MCP (Model Context Protocol) server tools.
The utility is based on the [FastMCP](https://github.com/jlowin/fastmcp) library, and acts as an
added layer on top.
## Installation
To install the **pylib2mcp** package, simply clone the repository and install it:
```
git clone https://github.com/Marios-Mamalis/pythonlibrary2mcp
cd pythonlibrary2mcp
uv pip install .
```
`uv` is highly recommended for installation, but `pip` also works.
## Usage
The utility can attach a single function, a list of functions, or be set to automatically
discover and attach all compatible routines from a module (except lambda functions) as MCP tools.
You can use this package as a regular Python module:
```python
import pylib2mcp
pylib2mcp.create_pylib_mcp(
libraries_and_funcs={
'transliterate': 'translit', # a single function, external library
'urllib.parse': ['quote', 'unquote'], # a list of functions
'math': None # all attachable routines in that module
},
server_name='Python function server'
).run(
transport='sse',
host='0.0.0.0',
port=8000
)
```
Or run it directly from the command line:
```bash
pylib2mcp run --library-functions transliterate:translit \
--library-functions urllib.parse:quote,unquote \
--library-functions math \
--name "Python function server"
--transport sse --host 0.0.0.0 --port 8000
```
### Behavior and limitations
The libraries containing the functions to be attached, must already be installed, if external.
Automatic attachment of Python functions as MCP tools is based on their signatures. Signatures with
unsupported I/O types are skipped. However, if a function lacks a signature, it is possible that
it will be attached as an MCP tool but won't function correctly, so it is best to test the attached
functions for expected behavior.
## Contributing
If you want to contribute to the project, install the development requirements by syncing the
project through the lockfile instead of doing a standard install.
Contributions should follow the Black formatting style and pass the test suite.