Skip to main content

A template (repository) for developing MCP servers in Python

Project description

Python 3.12+ pytest PyPI GitHub commits since latest release smithery badge

pymcp logo

Primarily to be used as a template repository for developing MCP servers with FastMCP in Python, PyMCP is somewhat inspired by the official everything MCP server in Typescript.

Components

The following components are available on this MCP server.

Tools

  1. greet
  • Greets the caller with a quintessential Hello World message.
  • Input(s)
    • name: string (optional): The name to greet. Default value is none.
  • Output(s)
    • TextContent with a UTC time-stamped greeting.
  1. generate_password
  • Generates a random password with specified length, optionally including special characters and conforming to the complexity requirements of at least one lowercase letter, one uppercase letter, and two digits. If special characters are included, it will also contain at least one such character.
  • Input(s)
    • length: integer: The length of the generated password. The value must be an integer between 8 and 64, both inclusive.
    • use_special_chars: boolean (optional): A flag to indicate whether the password should include special characters. Default value is False.
  • Output(s)
    • TextContent with the generated password.
  1. permutations
  • Calculates the number of ways to choose $k$ items from $n$ items without repetition and with order. If $k$ is not provided, it defaults to $n$.
  • Input(s)
    • n: integer: The number of items to choose from. This should be a non-zero, positive integer.
    • k: integer (optional): The number of items to choose. Default value is the value of n.
  • Output(s)
    • TextContent with number of ways to choose $k$ items from $n$, essentially ${}^{n}P_{k}$.
  1. pirate_summarise
  • Summarises the given text in a pirate style. This tool uses LLM client sampling. Hence, a sampling handler must exist on the client-side.
  • Input(s)
    • text: string: The text to summarise.
  • Output(s)
    • TextContent with the summary of text in pirate speak.
  1. vonmises_random
  • Generates a random number from the von Mises distribution. This tool uses client elicitation to obtain the parameter kappa ($\kappa$). Hence, an elicitation handler must exist on the client-side.
  • Input(s)
    • mu: float: The parameter $\mu$ between 0 and $2\pi$.
  • Output(s)
    • TextContent with the a random number from the von Mises distribution.

Resources

  1. resource_logo
  • Retrieves the Base64 encoded PNG logo of PyMCP along with its SHA3-512 hash.
  • URL: data://logo
  • Output(s)
    • TextContent with a Base64EncodedBinaryDataResponse Pydantic object with the following fields.
      • data: string: The Base64 encoded PNG logo of PyMCP.
      • hash: string: The hexadecimal encoded cryptographic hash of the raw binary data, which is represented by its Base64 encoded string equivalent in data. (The hex encoded hash value is expected to be 6414b58d9e44336c2629846172ec5c4008477a9c94fa572d3419c723a8b30eb4c0e2909b151fa13420aaa6a2596555b29834ac9b2baab38919c87dada7a6ef14.)
      • hash_algorithm: string: The cryptographic hash algorithm used, e.g., sha3_512.
  1. resource_logo_svg
  • Retrieves the SVG logo of PyMCP.
  • URL: data://logo_svg
  • Output(s)
    • TextContent with a the SVG data for the PyMCP logo.
  1. resource_unicode_modulo10
  • Computes the modulus 10 of a given number and returns a Unicode character representing the result. The character is chosen based on whether the modulus is odd or even. For odd modulus, it uses the Unicode characters ❶ (U+2776), ❸ (U+2778), ❺ (U+277A), ❼ (U+277C), and ❾ (U+277E). For even modulus, it uses the Unicode characters ⓪ (U+24EA), ② (U+2461), ④ (U+2463), ⑥ (U+2465), and ⑧ (U+2467).
  • URL: data://modulo10/{number}
  • Input(s)
    • number: integer: A positive integer between 1 and 1000, both inclusive.
  • Output(s)
    • TextContent with a string representing the correct Unicode character.

Prompts

  1. code_prompt
  • Get a prompt to write a code snippet in Python based on the specified task..
  • Input(s)
    • task: string: The description of the task for which a code implementation prompt will be generated.
  • Output(s)
    • PromptMessage with the role of a user and a content as a TextContent representing the prompt.

Installation

The directory where you clone this repository will be referred to as the working directory or WD hereinafter.

Install uv. To install the project with its minimal dependencies in a virtual environment, run the following in the WD. To install all non-essential dependencies (which are required for developing and testing), replace the --no-dev with the --all-groups flag in the following command.

uv sync --no-dev

Standalone usage

PyMCP can be started standalone as a MCP server with stdio transport by running the following. However, you are unlikely to use it this way.

uv run pymcp

Furthermore, being a template repository, the code deliberately does not implement streamable-http and sse transports.

Test with the MCP Inspector

The MCP Inspector is an official Model Context Protocol tool that can be used by developers to test and debug MCP servers. This is the most comprehensive way to explore the MCP server.

To use it, you must have Node.js installed. The best way to install and manage node as well as packages such as the MCP Inspector is to use the Node Version Manager (or, nvm). Once you have nvm installed, you can install and use the latest Long Term Release version of node by executing the following.

nvm install --lts
nvm use --lts

Following that, run the MCP Inspector and PyMCP by executing the following in the WD.

npx @modelcontextprotocol/inspector uv run pymcp

This will create a local URL at port 6274 with an authentication token, which you can copy and browse to on your browser. Once on the MCP Inspector UI, press Connect to connect to the MCP server. Thereafter, you can explore the tools available on the server.

Use it with Claude Desktop, Visual Studio, and so on

The server entry to run with stdio transport that you can use with systems such as Claude Desktop, Visual Studio Code, and so on is as follows.

{
    "command": "uv",
    "args": [
        "run",
        "pymcp"
    ]
}

Instead of having pymcp as the last item in the list of args, you may need to specify the full path to the script, e.g., WD/.venv/bin/pymcp.

Remotely hosted options

The currently available remotely hosted options are as follows.

Testing and coverage

To run the provided set of tests using pytest, execute the following in WD. Append the flag --capture=tee-sys to the following command to see the console output during the tests.

uv run --group test pytest tests/

To get a report on coverage while invoking the tests, run the following two commands.

uv run --group test coverage run -m pytest tests/
uv run coverage report

This will generate something like the following output.

Name                    Stmts   Miss  Cover
-------------------------------------------
src/pymcp/__init__.py       0      0   100%
src/pymcp/server.py        98      8    92%
tests/__init__.py           0      0   100%
tests/test_server.py      135      0   100%
-------------------------------------------
TOTAL                     233      8    97%

Contributing

Install pre-commit for Git by using the --all-groups flag for uv sync for the installation of PyMCP.

Then enable pre-commit by running the following in the WD.

pre-commit install

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT.

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

pymcp_template-0.1.3.tar.gz (65.2 kB view details)

Uploaded Source

Built Distribution

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

pymcp_template-0.1.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pymcp_template-0.1.3.tar.gz.

File metadata

  • Download URL: pymcp_template-0.1.3.tar.gz
  • Upload date:
  • Size: 65.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for pymcp_template-0.1.3.tar.gz
Algorithm Hash digest
SHA256 bcf8210937e2c4b1a5a6292b674872e49628ffee3949778c1944e331fb6b366b
MD5 b9cccaf14c37d14a6c3c3c6a1ab1b469
BLAKE2b-256 0b1bdd239adb98d031720c47439f98feae1d3cc9e714055cb84549b4041477b6

See more details on using hashes here.

File details

Details for the file pymcp_template-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pymcp_template-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 41ee54e29eadde69d04f016404e941489322a7dd802ba26b529a6b971d05f131
MD5 eaea964c09283c867a166a2d6084bf9e
BLAKE2b-256 5fc5ce67b9df30300f3f8333d52dccd0ef0e3b8e6918b2a1dfa05a67b8ec9e01

See more details on using hashes here.

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