Skip to content

Commit 2cb494b

Browse files
Merge pull request #2 from featureform/example/smack-server
Example/smack server
2 parents 321498a + 074b8a4 commit 2cb494b

File tree

6 files changed

+675
-0
lines changed

6 files changed

+675
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
smack-server:
3+
build: ./smack
4+
ports:
5+
- "8000:8000"
6+
restart: unless-stopped
7+
depends_on:
8+
- postgres
9+
environment:
10+
- DATABASE_URL=postgresql://postgres:postgres@postgres:5432/smack
11+
12+
postgres:
13+
image: postgres:15
14+
ports:
15+
- "5432:5432"
16+
volumes:
17+
- postgres_data:/var/lib/postgresql/data
18+
environment:
19+
- POSTGRES_PASSWORD=postgres
20+
- POSTGRES_USER=postgres
21+
- POSTGRES_DB=smack
22+
restart: unless-stopped
23+
24+
volumes:
25+
postgres_data:

examples/servers/smack/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.10-slim
2+
3+
# Set working directory in the container
4+
WORKDIR /app
5+
6+
# Install uv and tomli for TOML parsing
7+
RUN pip install --no-cache-dir uv tomli==2.0.1
8+
9+
# Copy pyproject.toml
10+
COPY pyproject.toml .
11+
12+
# Install dependencies using uv with --system flag
13+
RUN uv pip install --system --no-cache-dir .
14+
15+
# Copy the application code
16+
COPY . .
17+
18+
# Expose port for the server
19+
EXPOSE 8000
20+
21+
# Environment variables for PostgreSQL connection
22+
ENV DB_HOST=postgres \
23+
DB_NAME=smack \
24+
DB_USER=postgres \
25+
DB_PASSWORD=postgres \
26+
DB_PORT=5432
27+
28+
# Command to run the web server
29+
CMD ["python", "mcp_smack/server.py"]

examples/servers/smack/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# SMACK - Message Storage Service
2+
3+
SMACK is a simple messaging service with a persistent message store using PostgreSQL. It's designed to work with the Model Context Protocol (MCP) Inspector for easy testing and interaction.
4+
5+
## Overview
6+
7+
SMACK is built on the MCP Engine, a secure implementation of the Model Context Protocol (MCP) with authentication support. While MCP standardizes interactions between AI models and external systems, early implementations lacked key features for security, scalability, and reliability. MCP Engine addresses these by integrating OAuth 2.1, ensuring secure and seamless communication.
8+
9+
SMACK serves as a practical demonstration of the MCP Engine's capabilities by providing a basic yet functional messaging service. It highlights the importance of authentication and provides a hands-on experience with secure AI interactions.
10+
11+
For a visual representation of the architecture and how SMACK integrates with the MCP Engine, please refer to the diagram below:
12+
13+
<a href="https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/authorization/" target="_blank">
14+
<img src="https://cdn.prod.website-files.com/60cce6512b4ab924a0427124/67ec3d30ae1829e736099100_AD_4nXfpxfRMRgTM8glCYWi-YjhvxBvM3qAS73e58YRbCT8xtVnDwipEhT6NhLxssr5xH7jw-d6HoJByggT7QtOIsXYuG8MYbVtiV2aeNPiXDlIGjIF6zIKhaCrO4AdmGAUmuHLXgBzX.png" alt="MCP Authorization Flow" width="500">
15+
</a>
16+
17+
This diagram illustrates the flow of data and the role of authentication in ensuring secure interactions within the SMACK service.
18+
19+
We encourage you to explore SMACK to understand the critical role of authentication and scalability in MCP-based interactions and to experience firsthand the enhancements brought by the MCP Engine.
20+
21+
## Features
22+
23+
- OAuth 2.1 authentication
24+
- Persistent message storage using PostgreSQL
25+
- Docker containerization for easy deployment
26+
27+
## Prerequisites
28+
29+
- Docker and Docker Compose
30+
- MCP Inspector (for testing and interaction)
31+
- npx (optional)
32+
33+
## Quick Start
34+
35+
### 1. Clone the repository and navigate to the examples/smack directory
36+
37+
### 2. Start the service using Docker Compose:
38+
```bash
39+
docker-compose up --build
40+
```
41+
This will:
42+
- Build and start the SMACK server on port 8000
43+
- Start a PostgreSQL instance on port 5432
44+
- Create necessary volumes for data persistence
45+
46+
### 3. Connect to the service
47+
You can use our proxy server to connect SMACK to your client.
48+
Navigate to the proxy directory and build the main file:
49+
50+
```bash
51+
cd src/mcp/proxy
52+
go build main.go
53+
```
54+
55+
There are multiple ways to interact with SMACK:
56+
57+
#### a. Using the MCP Inspector
58+
In a separate terminal run
59+
60+
```bash
61+
npx @modelcontextprotocol/inspector ./main <server-url>
62+
```
63+
In this case the server url is http://localhost:8000/sse.
64+
65+
This will open the MCP inspector in your browser where you can list the tools and interact with the server.
66+
67+
#### b. Using Claude Desktop
68+
Create the config file if it doesn't exist:
69+
70+
```bash
71+
touch ~/Library/Application\ Support/Claude/claude_desktop_config.json
72+
```
73+
Add the following to the file:
74+
```json
75+
{
76+
"mcpServers": {
77+
"smack_mcp_server": {
78+
"command": "path/to/repo/mcp_engine/src/mcp/proxy/main",
79+
"args": [
80+
"http://localhost:8000/sse"
81+
]
82+
}
83+
}
84+
}
85+
```
86+
87+
Save the file and restart Claude Desktop. You should now see the SMACK server in the list of available servers.
88+
You can now use Claude to send messages and list messages on SMACK.
89+
90+
## Available Tools
91+
92+
### `list_messages()`
93+
Retrieves all posted messages from the database.
94+
95+
**Response Format:**
96+
```
97+
1. sender: message content
98+
2. sender: message content
99+
...
100+
```
101+
102+
### `post_message(sender: str, message: str)`
103+
Posts a new message to the database.
104+
105+
**Parameters:**
106+
- `sender`: The sender of the message
107+
- `message`: The text content you want to post
108+
109+
**Response:**
110+
- Success: "Message posted successfully: '{message}'"
111+
- Failure: Error message if the post failed

0 commit comments

Comments
 (0)