Skip to content

Commit 1196e54

Browse files
authored
Integrate Google Service Authentication (#14)
This pull request introduces the integration of Google OAuth2 and Gmail API into the project. It includes new commands, configurations, and services to handle OAuth2 authentication and Gmail operations. ### Google OAuth2 and Gmail API Integration: * [`cmd/devtest.go`](diffhunk://#diff-529f91fcc39baf08d02b15f11487937a89d21f559557465bc621bbc6c4dff0b6R1-R55): Added a new command `devtest` to run development tests, including setting up OAuth2 flow and Gmail API routes. * [`cmd/root.go`](diffhunk://#diff-ab967ab1a2f3a1b769106eeb7bfe892ef0e81d1d27811fa15be08e6749feee1fR28): Registered the new `devtest` command. * [`cmd/server.go`](diffhunk://#diff-ee2560d627cd77f1563972217a33ac39a4bf56fbf30d7f560fbb4199b9f70197R6-R9): Integrated Google OAuth2 and Gmail API into the server command, including setting up token storage and Gmail service. [[1]](diffhunk://#diff-ee2560d627cd77f1563972217a33ac39a4bf56fbf30d7f560fbb4199b9f70197R6-R9) [[2]](diffhunk://#diff-ee2560d627cd77f1563972217a33ac39a4bf56fbf30d7f560fbb4199b9f70197L72-R89) [[3]](diffhunk://#diff-ee2560d627cd77f1563972217a33ac39a4bf56fbf30d7f560fbb4199b9f70197L97-R114) [[4]](diffhunk://#diff-ee2560d627cd77f1563972217a33ac39a4bf56fbf30d7f560fbb4199b9f70197R124-R125) [[5]](diffhunk://#diff-ee2560d627cd77f1563972217a33ac39a4bf56fbf30d7f560fbb4199b9f70197L124-R151) ### Configuration Changes: * [`internal/config/config.go`](diffhunk://#diff-54c7c1af5fa8d5db4dc49f0e8e80e93ba2b1183ba4d5c9e2e5729e6deae6a3cdR4): Added new configuration fields for Google service settings. [[1]](diffhunk://#diff-54c7c1af5fa8d5db4dc49f0e8e80e93ba2b1183ba4d5c9e2e5729e6deae6a3cdR4) [[2]](diffhunk://#diff-54c7c1af5fa8d5db4dc49f0e8e80e93ba2b1183ba4d5c9e2e5729e6deae6a3cdR18) ### New Google Service Implementation: * [`internal/service/google/service.go`](diffhunk://#diff-465e8735f9ba61820c2731d7d716a64c9318b27f32fe4cbe125fa9e267097791R1-R130): Implemented `GoogleService` to handle OAuth2 flow, including methods for starting the OAuth process and handling callbacks. * [`internal/service/google/storage.go`](diffhunk://#diff-6f6d1b8b0bd0e34e84e35b400f3c4a867047e07b8e33bdde74e964b8c45b6eb8R1-R113): Added token storage implementations (`InMemoryStorage` and `FileTokenStorage`) for managing OAuth tokens. * [`internal/service/google/errors.go`](diffhunk://#diff-e58dc475377050ab63ecd6e3944a2ba93fa5f82fffc7a6f3ad6c899b1a755a0aR1-R9): Defined error types for Google service operations. ### Dependency Updates: * [`go.mod`](diffhunk://#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R31-R38): Updated dependencies to include necessary Google API and OAuth2 packages. [[1]](diffhunk://#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R31-R38) [[2]](diffhunk://#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R56-R64) [[3]](diffhunk://#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R88-R105) These changes collectively enable the application to authenticate users via Google OAuth2 and interact with the Gmail API, enhancing its functionality for email-related operations.
1 parent 116ca69 commit 1196e54

File tree

23 files changed

+990
-313
lines changed

23 files changed

+990
-313
lines changed

.env.example

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
/cmd/static
55

66
/.env.local.env.local
7+
/config.*.yaml
8+
!/config.example.yaml

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ COPY --from=builder /etc/passwd /etc/passwd
1919
# Copy the binary from builder
2020
COPY --from=builder /app/build/mcp /usr/local/bin/mcp
2121

22+
# Copy the example config file
23+
COPY --from=builder /app/config.example.yaml /etc/mcp/config.example.yaml
24+
2225
# Use non-root user
2326
USER app
2427

README.md

Lines changed: 148 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,129 @@
11
# MCP Kit - Model Context Protocol Toolkit
22

3-
## Overview
3+
This project is a playground for experimenting with the Model Context Protocol (MCP) and Large Language Models (LLMs).
44

55
The MCP Kit provides a platform that facilitates interaction with Large Language Models (LLMs) using the Model Context Protocol (MCP).
66
It enables AI assistants to interact with external tools and services, extending their capabilities beyond their confined contexts.
77
This toolkit offers a standardized way for AI models to communicate with external systems.
88

9-
## Key Features
9+
**Disclaimer**: This project is a proof-of-concept and is not intended for production use. Feel free to explore, experiment,
10+
and contribute to the project. For production systems, consider using separate, well-established components mentioned in this project
11+
and services tailored to your needs. For any questions or feedback, please open an issue or contact the maintainers.
12+
13+
## Components
14+
15+
### MCP Server
16+
17+
The **MCP Server** is a core component implementing the **Model Context Protocol (MCP)** specification. It facilitates structured communication between clients and AI/ML models by adhering to a standardized protocol.
18+
19+
#### Key Features:
20+
- **Protocol Compliance**: Fully compliant with the [MCP specification](https://modelcontextprotocol.io), ensuring interoperability.
21+
- **Event Streaming**: Supports Server-Sent Events (SSE) for real-time data streaming.
22+
- **Scalability**: Designed to handle concurrent requests and model interactions.
23+
24+
#### Technical Details:
25+
- **Library**: Built using `github.com/shaharia-lab/goai/mcp` (Go package).
26+
- **Documentation**: Detailed usage and API references available in the [GoAI Docs](https://github.com/shaharia-lab/goai/tree/main/docs).
27+
- **Resources**:
28+
- [MCP Repository](https://modelcontextprotocol.io)
29+
- [Go Package Documentation](https://pkg.go.dev/github.com/shaharia-lab/goai/mcp)
30+
31+
---
32+
33+
### MCP Client
34+
35+
The **MCP Client** acts as a configurable intermediary to connect applications to the MCP Server. It abstracts protocol complexities, enabling seamless integration with backend services.
36+
37+
#### Key Features:
38+
- **Protocol Adherence**: Implements the MCP specification for server compatibility.
39+
- **Configurability**: Supports custom configurations for connection timeouts, retries, and event handling.
40+
- **Real-Time Support**: Processes SSE streams from the MCP Server and forwards parsed data.
41+
42+
#### Technical Details:
43+
- **Library**: Shares the same `github.com/shaharia-lab/goai/mcp` library as the MCP Server.
44+
- **Documentation**: See [GoAI Docs](https://github.com/shaharia-lab/goai/tree/main/docs) for client-specific configurations.
45+
46+
---
47+
48+
### API Server
49+
50+
The **API Server** provides an HTTP layer for frontend applications to interact with the MCP ecosystem. It orchestrates communication between the frontend, MCP Client, and external AI services (e.g., LLMs).
51+
52+
#### Key Responsibilities:
53+
1. **Frontend Interface**: Exposes RESTful endpoints for user requests (e.g., prompts, model queries).
54+
2. **Request Routing**: Forwards incoming requests to the MCP Client and relays responses back.
55+
3. **LLM Integration**: Processes intermediate data from the MCP Client, invokes LLMs (e.g., for text generation), and formats final responses.
56+
57+
### MCP Kit Frontend:
58+
A dedicated frontend interface for interacting with the API Server, designed for testing and monitoring MCP workflows.
59+
60+
#### Technical Details:
61+
- **GitHub Repository**: [https://github.com/shaharia-lab/mcp-frontend](https://github.com/shaharia-lab/mcp-frontend)
62+
63+
## How Components Work Together
64+
65+
```mermaid
66+
flowchart LR
67+
Frontend["🖥️ MCP Kit Frontend"]
68+
API["🌐 HTTP API"]
69+
Client["📡 MCP Client"]
70+
Server["🖥️ MCP Server"]
71+
LLM["🧠 LLM"]
72+
73+
Frontend -- "A. Request" --> API
74+
API -- "B. Forward request" --> Client
75+
Client -- "C. Send request" --> Server
76+
Server -. "D. Return data via SSE events" .-> Client
77+
Client -- "E. Return data" --> API
78+
API -- "F. Process with LLM" --> LLM
79+
LLM -- "G. Return generated answer" --> API
80+
API -- "H. Final response" --> Frontend
81+
82+
subgraph Backend Process 1
83+
API
84+
Client
85+
LLM
86+
end
87+
88+
subgraph Backend Process 2
89+
Server
90+
end
91+
92+
style Frontend fill:#f9f,stroke:#333,stroke-width:2px
93+
style API fill:#9cf,stroke:#333,stroke-width:2px
94+
style Client fill:#9cf,stroke:#333,stroke-width:2px
95+
style Server fill:#fc9,stroke:#333,stroke-width:2px
96+
style LLM fill:#cfc,stroke:#333,stroke-width:2px
97+
```
1098

11-
* **API Server**: Provides LLM endpoints to interact with AI models.
12-
* **MCP Client**: Configurable client to connect to the MCP server.
13-
* **Tools**: There are many tools already implemented to access external systems (i.e: filesystem, git, github, postgresql, etc..), and you can easily add more.
14-
* **Interactive Chat Interface**: Provides an interactive chat interface for users to interact with the AI model.
15-
* **Chat History**: Implements in-memory storage for maintaining chat history.
16-
* **LLM Providers**: Supports Anthropic, OpenAI, Amazon Bedrock, Cohere, Meta Llama, Mistral, and DeepSeek models. You can integrate more models easily.
99+
## Demo
17100

18101
<video src="https://github.com/user-attachments/assets/81804a29-e896-4f65-a929-05ac6a6aa92a" controls title="MCP Kit in action"></video>
19102

20-
## Architecture
21-
22-
The MCP Kit follows a client-server architecture:
23-
24-
1. **Client**: Sends user requests to the MCP server.
25-
2. **Server**: Processes requests, coordinates with AI models, and manages tool execution.
26-
27-
### Request Flow
28-
29-
1. The client sends a user query to the MCP server.
30-
2. The server passes the query to the LLM API.
31-
3. The LLM determines if tools are needed.
32-
4. If tools are needed:
33-
* The LLM sends a request with tool parameters.
34-
* The MCP server executes the tools.
35-
* The tool output is returned to the LLM.
36-
* This loop continues until no more tools are needed.
37-
5. The final response is sent back to the client.
38-
39-
## Tools
40-
41-
The kit includes a variety of tools:
42-
43-
* **Git Tools**: `git_status`, `git_diff`, `git_commit`, `git_add`, `git_log`, etc..
44-
* **File System Tools**: `filesystem_list_directory`, `filesystem_read_file`, `filesystem_write_file`, `filesystem_get_file_info`.
45-
* **GitHub Tools**: `github_create_repository`, `github_create_issue`, `github_get_file_contents`, `github_search_repositories` etc.
46-
* **PostgreSQL Tools**: `postgresql_execute_query`, `postgresql_table_schema`, `postgresql_execute_query_with_explain`.
47-
48-
## Configuration
49-
50-
The configuration is loaded via environment variables. Key configuration parameters include:
51-
52-
* `API_SERVER_PORT`: Port for the API server (default: 8081).
53-
* `MCP_SERVER_URL`: URL for the MCP server (default: `http://localhost:8080/events`).
54-
* `MCP_SERVER_PORT`: Port for the MCP server (default: 8080).
55-
* `TOOLS_ENABLED`: List of enabled tools (default: `get_weather`).
103+
Feel free to explore the [MCP Kit Frontend](https://github.com/shaharia-lab/mcp-frontend) project.
56104

57105
## Getting Started
58106

59107
### Prerequisites
60108

61-
* Go installed
62-
* [Include any other prerequisites]
109+
* Go installed (for building from source)
110+
* Docker installed (optional)
63111

64112
### Installation
65113

66-
#### Load .env file
114+
#### Create a configuration file
67115

68-
```bash
69-
cp .env.example .env.local
70-
export $(cat .env.local | grep -v '^#' | xargs)
116+
You can copy `config.example.yaml` to `config.local.yaml` and update the values as needed.
117+
118+
You can also reference the environment variables in the configuration file with the following syntax:
119+
120+
```yaml
121+
google:
122+
client_id: "${GOOGLE_CLIENT_ID}"
71123
```
72124
125+
Here `${GOOGLE_CLIENT_ID}` will be replaced with the value of the `GOOGLE_CLIENT_ID` environment variable.
126+
73127
#### Using Source Code
74128

75129
```bash
@@ -81,23 +135,24 @@ make build
81135
##### Running the MCP Server
82136

83137
```bash
84-
./mcp server
138+
./mcp server --config config.local.yaml
85139
```
86140

87141
##### Running the API Server
88142

89143
```bash
90-
./mcp api
144+
./mcp api --config config.local.yaml
91145
```
92146

93-
#### Using Docker
147+
#### Run Components Separately Using Docker
94148

95149
```bash
96150
docker pull ghcr.io/shaharia-lab/mcp-kit:$VERSION
97151
98152
# Run MCP server
99153
docker run -d \
100154
--name mcp-server \
155+
-v $(pwd)/config.local.yaml:/config/config.yaml \
101156
-p 8080:8080 \
102157
-e MCP_SERVER_PORT=8080 \
103158
-e GITHUB_TOKEN=$GITHUB_TOKEN \
@@ -107,11 +162,12 @@ docker run -d \
107162
-e AUTH_CALLBACK_URL=$AUTH_CALLBACK_URL \
108163
-e AUTH_TOKEN_TTL=24h \
109164
-e AUTH_AUDIENCE=$AUTH_AUDIENCE \
110-
ghcr.io/shaharia-lab/mcp-kit:$VERSION server
165+
ghcr.io/shaharia-lab/mcp-kit:$VERSION server --config /config/config.yaml
111166
112167
# Run API server
113168
docker run -d \
114169
--name mcp-client \
170+
-v $(pwd)/config.local.yaml:/config/config.yaml \
115171
--add-host=host.docker.internal:host-gateway \
116172
-e ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY \
117173
-e MCP_SERVER_URL=http://host.docker.internal:8080/events \
@@ -122,7 +178,7 @@ docker run -d \
122178
-e AUTH_TOKEN_TTL=24h \
123179
-e AUTH_AUDIENCE=$AUTH_AUDIENCE \
124180
-p 8081:8081 \
125-
ghcr.io/shaharia-lab/mcp-kit:$VERSION api
181+
ghcr.io/shaharia-lab/mcp-kit:$VERSION api --config /config/config.yaml
126182
127183
## Running the MCP Kit Frontend
128184
@@ -133,7 +189,9 @@ docker run -d \
133189
ghcr.io/shaharia-lab/mcp-frontend:latest
134190
```
135191

136-
### Using Docker Compose
192+
### Using Docker Compose (Advanced)
193+
194+
If you want to run all the components together with basic observability and monitoring, you can use the provided `docker-compose.yml` file.
137195

138196
```bash
139197
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
@@ -144,10 +202,41 @@ docker-compose up -d
144202
```
145203

146204
### Accessing the UI
147-
http://localhost:3001
148205

149-
Visit `http://localhost:8081` to access the UI interface to interact with the AI model.
206+
http://localhost:3001
150207

151208
### Interacting with the API
152209

153-
OpenAPI schema is available in `openapi.yaml`.
210+
OpenAPI schema is available in `openapi.yaml`.
211+
212+
## Contributing
213+
214+
We welcome contributions to the project! If you'd like to contribute, please follow these steps:
215+
216+
1. **Fork the repository**: Click the "Fork" button at the top of [this repository](https://github.com/shaharia-lab/mcp-kit) to create your own copy.
217+
2. **Clone your fork**: Clone your fork to your local machine using:
218+
```bash
219+
git clone https://github.com/your-username/mcp-kit.git
220+
```
221+
3. **Create a branch**: Create a new branch for your changes:
222+
```bash
223+
git checkout -b feature/your-feature-name
224+
```
225+
4. **Make your changes**: Implement your changes, ensure your code is clean and well-documented.
226+
5. **Test your changes**: Make sure all existing tests pass and write new ones if needed. Run the tests using:
227+
```bash
228+
make test
229+
```
230+
6. **Submit a pull request**: Push your changes to your forked repository and create a pull request to the `main` branch
231+
of this repository. Please include a clear description of your changes.
232+
233+
We recommend reading the [Conventional Commits](https://www.conventionalcommits.org/) specification to properly format
234+
your commit messages.
235+
236+
### Code of Conduct
237+
238+
Please note that by contributing to this project, you agree to adhere to our [Code of Conduct](./CODE_OF_CONDUCT.md).
239+
240+
## License
241+
242+
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details. Each component may have its own license, so please check the respective repositories/libraries for more information.

0 commit comments

Comments
 (0)