Skip to main content
Glama
stevensu1977

MCP Example

by stevensu1977

MCP-Example

A demonstration project implementing the Model Context Protocol (MCP), showcasing client-server communication with various functionalities including web content fetching and system monitoring.

Features

  • Web content fetching and parsing

  • System information monitoring

  • Real-time server-sent events (SSE) communication

  • MCP protocol implementation

  • Resource management and tool execution

Related MCP server: Hello World MCP Server

Requirements

  • Python 3.10+

  • Dependencies (install via pip):

    • httpx

    • beautifulsoup4

    • uvicorn

    • psutil

    • mcp-sdk

Installation

  1. Clone the repository:

git clone https://github.com/stevensu1977/mcp-example.git
cd mcp-example.git
  1. Create and activate a virtual environment:

python -m venv .venv
source .venv/bin/activate  # On Windows, use: .venv\Scripts\activate
  1. Install dependencies:

pip install -r requirements.txt

Usage

  1. Start the SSE server:

#There have two types server , sse and stdio
python sse/exampe_server.py

The server will start on http://localhost:8000

  1. In a separate terminal, run the SSE client:

python sse/exampe_client.py
(.venv) ➜  mcp-example git:(main) ✗ python sse/example_client.py
Connecting to http://0.0.0.0:8000/sse
nextCursor=None tools=[Tool(name='fetch', description='Fetches a website and returns its content', inputSchema={'type': 'object', 'required': ['url'], 'properties': {'url': {'type': 'string', 'description': 'URL to fetch'}}})]
content=[TextContent(type='text', text='<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n    <meta charset="utf-8" />\n    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n    <meta name="viewport" content="width=device-width, initial-scale=1" />\n    <style type="text/css">\n    body {\n        background-color: #f0f0f2;\n        margin: 0;\n        padding: 0;\n        font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;\n        \n    }\n    div {\n        width: 600px;\n        margin: 5em auto;\n        padding: 2em;\n        background-color: #fdfdff;\n        border-radius: 0.5em;\n        box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);\n    }\n    a:link, a:visited {\n        color: #38488f;\n        text-decoration: none;\n    }\n    @media (max-width: 700px) {\n        div {\n            margin: 0 auto;\n            width: auto;\n        }\n    }\n    </style>    \n</head>\n\n<body>\n<div>\n    <h1>Example Domain</h1>\n    <p>This domain is for use in illustrative examples in documents. You may use this\n    domain in literature without prior coordination or asking for permission.</p>\n    <p><a href="https://www.iana.org/domains/example">More information...</a></p>\n</div>\n</body>\n</html>\n')] isError=False

The client will connect to the server and demonstrate various functionalities including:

  • Fetching external web content

Protocol Implementation

This project implements the Model Context Protocol (MCP), providing a framework for:

  • Server-Sent Events (SSE) based communication

  • Resource management

  • Tool execution

  • Client-server interaction

License

See the LICENSE file for details.

Related MCP Connectors

Related MCP Servers

  • A
    license
    C
    quality
    B
    maintenance
    A simple MCP server that facilitates website fetching through a configurable server platform using stdio or SSE transport, allowing integration with tools like Cursor for streamlined access.
    2
    38
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A demonstration MCP server supporting both Stdio and SSE transports, providing example tools (echo, add, time, UUID generation) and resources for learning and testing MCP implementations.
    8 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A simple Model Context Protocol server demonstration that provides SSE streaming communication and basic message handling with a Hello World example.
    Apache 2.0

Appeared in Searches