|
| 1 | +# Simple MCP Server |
| 2 | + |
| 3 | +A FastAPI-based Model Context Protocol (MCP) server that demonstrates how to deploy MCP tools on Posit Connect. This extension showcases Connect's ability to host MCP servers that can be consumed by AI assistants and other MCP clients. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This extension demonstrates Connect's capability to host Model Context Protocol servers, enabling LLMs to access and execute tools remotely. The Simple MCP Server provides a collection of data analysis tools and Connect integration capabilities, making it an ideal companion for AI-powered applications like the [Simple Shiny Chat](../simple-shiny-chat-with-mcp/README.md) extension. |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- **FastAPI-Based MCP Server**: Built on FastAPI with streamable HTTP transport for efficient MCP communication |
| 14 | +- **Data Analysis Tools**: Includes tools for dataset operations and summary statistics |
| 15 | +- **Connect Integration**: Provides tools that interact with Connect's API |
| 16 | +- **Interactive Documentation**: Clean web interface that displays available tools and their parameters |
| 17 | +- **Copy-to-Clipboard Endpoint**: Easy sharing of MCP server URLs |
| 18 | +- **Automatic Tool Discovery**: MCP clients can dynamically discover and use available tools |
| 19 | + |
| 20 | +## Available Tools |
| 21 | + |
| 22 | +### Dataset Operations |
| 23 | +- **`list_known_datasets`**: Lists all available datasets in the server |
| 24 | +- **`calculate_summary_statistics`**: Generates comprehensive summary statistics for specified datasets |
| 25 | + |
| 26 | +### Connect Integration |
| 27 | +- **`connect_whoami`**: Calls the Connect `/me` endpoint using API key authentication |
| 28 | + |
| 29 | +### Sample Datasets |
| 30 | +- **Iris Dataset**: Classic machine learning dataset from scikit-learn |
| 31 | +- **Sample Data**: Simple demonstration dataset with mixed data types |
| 32 | + |
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +### Connect Requirements |
| 36 | + |
| 37 | +1. **Minimum Connect Version**: 2025.04.0 or later |
| 38 | +2. **API Publishing**: Must be enabled on your Connect server |
| 39 | +3. **Python 3.10+**: Required for the MCP SDK |
| 40 | + |
| 41 | +## Deployment |
| 42 | + |
| 43 | +### 1. Deploy the Extension |
| 44 | +Deploy this extension to your Connect server. If you are deploying through the Connect Gallery, see the [Gallery documentation](https://docs.posit.co/connect/user/publishing-connect-gallery/). |
| 45 | + |
| 46 | +### 2. Access the Server |
| 47 | +Once deployed, the extension provides: |
| 48 | +- **Web Interface**: Visit the content URL to see available tools and copy the MCP endpoint |
| 49 | +- **MCP Endpoint**: Located at `{direct-content-url}/mcp` for MCP client connections |
| 50 | + |
| 51 | +Please note that it is recommended to set the minimum number of instances/processes for this application to >= 1 in the content settings. This will ensure that the MCP server is always available for clients to connect. See the [content process configuration documentation](https://docs.posit.co/connect/user/content-settings/index.html#process-configurations). |
| 52 | + |
| 53 | +### 3. Use with MCP Clients |
| 54 | +The server can be consumed by any MCP-compatible client, including: |
| 55 | +- [Simple Shiny Chat](../simple-shiny-chat-with-mcp/README.md) extension |
| 56 | +- Local MCP clients |
| 57 | +- AI development environments that support MCP |
| 58 | + |
| 59 | +## Usage Examples |
| 60 | + |
| 61 | +### With Simple Shiny Chat Extension |
| 62 | + |
| 63 | +1. Deploy both the Simple MCP Server and Simple Shiny Chat extensions |
| 64 | +2. In the chat application, add the MCP server URL from this extension |
| 65 | +3. Ask the AI assistant to: |
| 66 | + - "What datasets are available?" |
| 67 | + - "Calculate summary statistics for the iris dataset" |
| 68 | + - "Show me information about my Connect user account" |
| 69 | + |
| 70 | +### With Other MCP Clients |
| 71 | + |
| 72 | +Connect to the MCP endpoint at `{your-connect-server}/content/{content-guid}/mcp` and use the available tools programmatically. |
| 73 | + |
| 74 | +If you are not using the Simple Shiny Chat extension to connect to this MCP server, you will need to ensure that you can specify your Connect API key in both the `x-mcp-authorization` header and the `authorization` header for Connect API calls. Some MCP clients may not support that directly today (June 2025). |
| 75 | + |
| 76 | +## Architecture |
| 77 | + |
| 78 | +The application consists of several key components: |
| 79 | + |
| 80 | +- **FastMCP Framework**: Handles MCP protocol implementation and tool registration |
| 81 | +- **FastAPI Application**: Provides HTTP transport and web interface |
| 82 | +- **Tool Implementations**: Individual functions that implement business logic |
| 83 | +- **Template Engine**: Jinja2 templates for the documentation interface |
| 84 | +- **Dataset Storage**: In-memory storage for demonstration datasets |
| 85 | + |
| 86 | +## Troubleshooting |
| 87 | + |
| 88 | +### Deployment Issues |
| 89 | +- Ensure your Connect server supports API publishing |
| 90 | +- Verify Python 3.10+ is available in your Connect environment |
| 91 | +- Check that all dependencies are properly installed |
| 92 | + |
| 93 | +### MCP Client Connection Issues |
| 94 | +- Verify the MCP endpoint URL is correct (`{content-url}/mcp`) |
| 95 | +- Ensure the server is accessible from the client |
| 96 | +- Check Connect content permissions |
| 97 | + |
| 98 | +### Tool Execution Errors |
| 99 | +- Review tool parameter requirements and types |
| 100 | +- Verify API key format for Connect integration tools |
| 101 | +- Check Connect logs for detailed error messages |
| 102 | + |
| 103 | +## Integration with Simple Shiny Chat |
| 104 | + |
| 105 | +This MCP server is designed to work seamlessly with the [Simple Shiny Chat](../simple-shiny-chat-with-mcp/README.md) extension: |
| 106 | + |
| 107 | +1. Deploy both extensions to your Connect server |
| 108 | +2. Configure the chat application with appropriate LLM credentials |
| 109 | +3. Register this MCP server in the chat interface |
| 110 | +4. Start conversing with AI assistants that can use these tools |
| 111 | + |
| 112 | +## Related Resources |
| 113 | + |
| 114 | +- [Model Context Protocol Documentation](https://modelcontextprotocol.io/) |
| 115 | +- [FastMCP Framework](https://github.com/jlowin/fastmcp) |
| 116 | +- [MCP Framework](https://github.com/modelcontextprotocol/python-sdk) |
| 117 | +- [FastAPI Documentation](https://fastapi.tiangolo.com/) |
| 118 | +- [Simple Shiny Chat Extension](../simple-shiny-chat-with-mcp/README.md) |
| 119 | +- [Posit Connect Extension Gallery Guide](https://docs.posit.co/connect/admin/connect-gallery/index.html) |
| 120 | + |
| 121 | +## Support |
| 122 | + |
| 123 | +For issues specific to this extension, please check the [Connect Extensions repository](https://github.com/posit-dev/connect-extensions). |
0 commit comments