Skip to content

Commit 0ac891f

Browse files
authored
Refactor tool configuration and initialization (#18)
Introduce a centralized tools registry to manage tool configurations and initialization, removing redundant setup logic. This update enhances modularity, simplifies tool integration, and ensures configuration validation and default setup consistency for all tools.
1 parent 1196e54 commit 0ac891f

File tree

8 files changed

+420
-70
lines changed

8 files changed

+420
-70
lines changed

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# MCP Kit - Model Context Protocol Toolkit
1+
# MCP Kit - Model Context Protocol Toolkit 🌐🤖
22

3-
This project is a playground for experimenting with the Model Context Protocol (MCP) and Large Language Models (LLMs).
3+
🔬 A cutting-edge toolkit for experimenting with Large Language Models (LLMs) and the Model Context Protocol (MCP).
44

5-
The MCP Kit provides a platform that facilitates interaction with Large Language Models (LLMs) using the Model Context Protocol (MCP).
6-
It enables AI assistants to interact with external tools and services, extending their capabilities beyond their confined contexts.
7-
This toolkit offers a standardized way for AI models to communicate with external systems.
5+
## Overview 🌟
6+
7+
MCP Kit is an innovative platform designed to revolutionize AI model interactions by providing a standardized, extensible framework for communication between AI assistants and external tools/services. It enables developers to build intelligent, context-aware applications with seamless integration across various AI models and services.
88

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
119
and services tailored to your needs. For any questions or feedback, please open an issue or contact the maintainers.
1210

1311
## Components
@@ -102,7 +100,7 @@ flowchart LR
102100

103101
Feel free to explore the [MCP Kit Frontend](https://github.com/shaharia-lab/mcp-frontend) project.
104102

105-
## Getting Started
103+
## Getting Started 🚀
106104

107105
### Prerequisites
108106

@@ -237,6 +235,17 @@ your commit messages.
237235

238236
Please note that by contributing to this project, you agree to adhere to our [Code of Conduct](./CODE_OF_CONDUCT.md).
239237

238+
## Monitoring and Observability
239+
240+
MCP Kit comes with built-in monitoring and observability features using popular open-source tools:
241+
242+
- **Prometheus**: For metrics collection and monitoring
243+
- **Grafana**: For visualization and dashboards
244+
- **Loki**: For log aggregation
245+
- **Promtail**: For log shipping and collection
246+
247+
These tools are pre-configured in the `monitoring/` directory and can be easily deployed using Docker Compose.
248+
240249
## License
241250

242251
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.

cmd/server.go

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ package cmd
33
import (
44
"context"
55
"fmt"
6-
"github.com/shaharia-lab/mcp-kit/internal/config"
7-
86
"github.com/shaharia-lab/goai/mcp"
9-
goaiObs "github.com/shaharia-lab/goai/observability"
107
"github.com/shaharia-lab/mcp-kit/internal/prompt"
118
"github.com/shaharia-lab/mcp-kit/internal/tools"
12-
mcptools "github.com/shaharia-lab/mcp-tools"
139
"github.com/spf13/cobra"
1410
"go.opentelemetry.io/otel"
1511
"go.opentelemetry.io/otel/codes"
@@ -75,14 +71,19 @@ func NewServerCmd() *cobra.Command {
7571
if err != nil {
7672
logger.Fatalf("Failed to create Gmail service: %v", err)
7773
}
78-
toolsLists := setupTools(container.LogrusLoggerImpl, gmailSvc, container.Config)
7974

8075
err = container.BaseMCPServer.AddPrompts(prompt.MCPPromptsRegistry...)
8176
if err != nil {
8277
return fmt.Errorf("failed to add prompts: %w", err)
8378
}
8479

85-
err = container.BaseMCPServer.AddTools(toolsLists...)
80+
toolsRegistry := tools.NewRegistry(container.Config.Tools, container.LogrusLoggerImpl, gmailSvc)
81+
err = toolsRegistry.Init()
82+
if err != nil {
83+
return fmt.Errorf("failed to initialize tools registry: %w", err)
84+
}
85+
86+
err = container.BaseMCPServer.AddTools(toolsRegistry.GetToolLists()...)
8687
if err != nil {
8788
return fmt.Errorf("failed to add tools: %w", err)
8889
}
@@ -99,46 +100,3 @@ func NewServerCmd() *cobra.Command {
99100
},
100101
}
101102
}
102-
103-
func setupTools(logger goaiObs.Logger, gmailService *gmail.Service, config *config.Config) []mcp.Tool {
104-
ts := tools.MCPToolsRegistry
105-
106-
ghConfig := mcptools.NewGitHubTool(logger, mcptools.GitHubConfig{})
107-
fileSystem := mcptools.NewFileSystem(logger, mcptools.FileSystemConfig{})
108-
docker := mcptools.NewDocker(logger)
109-
git := mcptools.NewGit(logger, mcptools.GitConfig{})
110-
curl := mcptools.NewCurl(logger, mcptools.CurlConfig{})
111-
postgres := mcptools.NewPostgreSQL(logger, mcptools.PostgreSQLConfig{})
112-
113-
ts = append(
114-
ts,
115-
116-
// Curl tools
117-
curl.CurlAllInOneTool(),
118-
119-
// Git tools
120-
git.GitAllInOneTool(),
121-
122-
// Docker tools
123-
docker.DockerAllInOneTool(),
124-
125-
// File system tools
126-
fileSystem.FileSystemAllInOneTool(),
127-
128-
// GitHub tools
129-
ghConfig.GetIssuesTool(),
130-
ghConfig.GetPullRequestsTool(),
131-
ghConfig.GetRepositoryTool(),
132-
ghConfig.GetSearchTool(),
133-
134-
// PostgreSQL tools
135-
postgres.PostgreSQLAllInOneTool(),
136-
)
137-
138-
if config.GoogleServiceConfig.Enabled {
139-
gmailTool := mcptools.NewGmail(logger, gmailService, mcptools.GmailConfig{})
140-
ts = append(ts, gmailTool.GmailAllInOneTool())
141-
}
142-
143-
return ts
144-
}

config.example.yaml

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,57 @@ google:
3131
- "https://www.googleapis.com/auth/userinfo.profile"
3232
state_cookie: "static-value-for-now"
3333
token_source_file: "/tmp/google_auth_token_source.json"
34-
enabled: false
34+
enabled: false
35+
36+
tools:
37+
get_wether:
38+
enabled: true
39+
postgres:
40+
enabled: true
41+
databases:
42+
- name: "mcp_kit"
43+
host: "localhost"
44+
username: "root"
45+
password: "root"
46+
port: 5432
47+
sslmode: "disable"
48+
github_repository:
49+
enabled: true
50+
token: "${GITHUB_TOKEN}"
51+
github_issues:
52+
enabled: true
53+
token: "${GITHUB_TOKEN}"
54+
github_pull_requests:
55+
enabled: true
56+
token: "${GITHUB_TOKEN}"
57+
github_search:
58+
enabled: true
59+
token: "${GITHUB_TOKEN}"
60+
filesystem:
61+
enabled: true
62+
allowed_directory: "/tmp"
63+
blocked_pattern:
64+
- "secret"
65+
- "password"
66+
git:
67+
enabled: true
68+
default_repo_path: "/tmp"
69+
blocked_commands:
70+
- "push"
71+
- "pull"
72+
- "fetch"
73+
curl:
74+
enabled: true
75+
blocked_methods:
76+
- "POST"
77+
- "PUT"
78+
- "DELETE"
79+
bash:
80+
enabled: true
81+
sed:
82+
enabled: true
83+
grep:
84+
enabled: true
85+
gmail:
86+
enabled: true
87+
token: "${GMAIL_TOKEN}"

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ require (
1313
github.com/fatih/color v1.18.0
1414
github.com/go-chi/chi/v5 v5.2.1
1515
github.com/go-chi/cors v1.2.1
16+
github.com/go-playground/validator/v10 v10.25.0
1617
github.com/google/uuid v1.6.0
1718
github.com/google/wire v0.6.0
1819
github.com/openai/openai-go v0.1.0-alpha.61
1920
github.com/prometheus/client_golang v1.21.1
2021
github.com/shaharia-lab/goai v0.12.0
21-
github.com/shaharia-lab/mcp-tools v0.0.4
22+
github.com/shaharia-lab/mcp-tools v0.0.5
2223
github.com/sirupsen/logrus v1.9.3
2324
github.com/spf13/cobra v1.9.1
2425
github.com/spf13/viper v1.20.0
@@ -55,9 +56,12 @@ require (
5556
github.com/davecgh/go-spew v1.1.1 // indirect
5657
github.com/felixge/httpsnoop v1.0.4 // indirect
5758
github.com/fsnotify/fsnotify v1.8.0 // indirect
59+
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
5860
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
5961
github.com/go-logr/logr v1.4.2 // indirect
6062
github.com/go-logr/stdr v1.2.2 // indirect
63+
github.com/go-playground/locales v0.14.1 // indirect
64+
github.com/go-playground/universal-translator v0.18.1 // indirect
6165
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
6266
github.com/google/go-github/v60 v60.0.0 // indirect
6367
github.com/google/go-querystring v1.1.0 // indirect
@@ -67,6 +71,7 @@ require (
6771
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.3 // indirect
6872
github.com/inconshreveable/mousetrap v1.1.0 // indirect
6973
github.com/klauspost/compress v1.18.0 // indirect
74+
github.com/leodido/go-urn v1.4.0 // indirect
7075
github.com/lib/pq v1.10.9 // indirect
7176
github.com/mattn/go-colorable v0.1.14 // indirect
7277
github.com/mattn/go-isatty v0.0.20 // indirect

go.sum

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
6262
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
6363
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
6464
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
65+
github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM=
66+
github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8=
6567
github.com/go-chi/chi/v5 v5.2.1 h1:KOIHODQj58PmL80G2Eak4WdvUzjSJSm0vG72crDCqb8=
6668
github.com/go-chi/chi/v5 v5.2.1/go.mod h1:L2yAIGWB3H+phAw1NxKwWM+7eUH/lU8pOMm5hHcoops=
6769
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
@@ -77,6 +79,14 @@ github.com/go-pg/pg/v10 v10.11.0 h1:CMKJqLgTrfpE/aOVeLdybezR2om071Vh38OLZjsyMI0=
7779
github.com/go-pg/pg/v10 v10.11.0/go.mod h1:4BpHRoxE61y4Onpof3x1a2SQvi9c+q1dJnrNdMjsroA=
7880
github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4mU=
7981
github.com/go-pg/zerochecker v0.2.0/go.mod h1:NJZ4wKL0NmTtz0GKCoJ8kym6Xn/EQzXRl2OnAe7MmDo=
82+
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
83+
github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
84+
github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA=
85+
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
86+
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
87+
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
88+
github.com/go-playground/validator/v10 v10.25.0 h1:5Dh7cjvzR7BRZadnsVOzPhWsrwUr0nmsZJxEAnFLNO8=
89+
github.com/go-playground/validator/v10 v10.25.0/go.mod h1:GGzBIJMuE98Ic/kJsBXbz1x/7cByt++cQ+YOuDM5wus=
8090
github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss=
8191
github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
8292
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
@@ -126,6 +136,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
126136
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
127137
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
128138
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
139+
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
140+
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
129141
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
130142
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
131143
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
@@ -136,8 +148,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
136148
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
137149
github.com/openai/openai-go v0.1.0-alpha.61 h1:dLJW1Dk15VAwm76xyPsiPt/Ky94NNGoMLETAI1ISoBY=
138150
github.com/openai/openai-go v0.1.0-alpha.61/go.mod h1:3SdE6BffOX9HPEQv8IL/fi3LYZ5TUpRYaqGQZbyk11A=
139-
github.com/openai/openai-go v0.1.0-alpha.63 h1:bOlYE6NJcPdjG3OMl9rZnxJrxmwcG6zlEKOD1MHP9Is=
140-
github.com/openai/openai-go v0.1.0-alpha.63/go.mod h1:3SdE6BffOX9HPEQv8IL/fi3LYZ5TUpRYaqGQZbyk11A=
141151
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
142152
github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc=
143153
github.com/pgvector/pgvector-go v0.3.0 h1:Ij+Yt78R//uYqs3Zk35evZFvr+G0blW0OUN+Q2D1RWc=
@@ -159,8 +169,8 @@ github.com/sagikazarmark/locafero v0.8.0 h1:mXaMVw7IqxNBxfv3LdWt9MDmcWDQ1fagDH91
159169
github.com/sagikazarmark/locafero v0.8.0/go.mod h1:UBUyz37V+EdMS3hDF3QWIiVr/2dPrx49OMO0Bn0hJqk=
160170
github.com/shaharia-lab/goai v0.12.0 h1:s177idIsM6GJhX3JJmyZRZ+4ve5pJnQ/QL3FaC4fMsc=
161171
github.com/shaharia-lab/goai v0.12.0/go.mod h1:EKzvGwFBTL8eLUIw3pTA+X18IMjfy5mncFQXhvQCnAo=
162-
github.com/shaharia-lab/mcp-tools v0.0.4 h1:va0aYPLuuhS+IhXXS1UtEHPtlyGOfukplXjYgNIws00=
163-
github.com/shaharia-lab/mcp-tools v0.0.4/go.mod h1:fcAmptmJ+RhK7zwAM+dpIr6cCOtjJyn3yKjvPj98DYw=
172+
github.com/shaharia-lab/mcp-tools v0.0.5 h1:Hwfigbu0CVLhGHDuqZpFxmUBGEfHiHsYj9phiP/ZQbM=
173+
github.com/shaharia-lab/mcp-tools v0.0.5/go.mod h1:fcAmptmJ+RhK7zwAM+dpIr6cCOtjJyn3yKjvPj98DYw=
164174
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
165175
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
166176
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=

internal/config/config.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
package config
22

33
import (
4+
"fmt"
5+
"github.com/shaharia-lab/mcp-kit/internal/tools"
46
"strings"
57
"time"
68

79
"github.com/spf13/viper"
810
)
911

1012
type Config struct {
11-
APIServerPort int `mapstructure:"api_server_port"`
12-
MCPServerURL string `mapstructure:"mcp_server_url"`
13-
MCPServerPort int `mapstructure:"mcp_server_port"`
14-
ToolsEnabled []string `mapstructure:"tools_enabled"`
15-
Tracing TracingConfig `mapstructure:"tracing"`
16-
Auth AuthConfig `mapstructure:"auth"`
17-
GoogleServiceConfig GoogleConfig `mapstructure:"google"`
13+
APIServerPort int `mapstructure:"api_server_port"`
14+
MCPServerURL string `mapstructure:"mcp_server_url"`
15+
MCPServerPort int `mapstructure:"mcp_server_port"`
16+
ToolsEnabled []string `mapstructure:"tools_enabled"`
17+
Tracing TracingConfig `mapstructure:"tracing"`
18+
Auth AuthConfig `mapstructure:"auth"`
19+
GoogleServiceConfig GoogleConfig `mapstructure:"google"`
20+
Tools *tools.ToolsConfig `yaml:"tools" validate:"required"`
1821
}
1922

2023
// TracingConfig holds the configuration for the tracing service
@@ -54,6 +57,7 @@ func Load(configFile string) (*Config, error) {
5457
var cfg Config
5558

5659
setDefaults()
60+
tools.SetDefaults(viper.GetViper())
5761

5862
// Configure Viper
5963
viper.SetConfigType("yaml")
@@ -73,6 +77,11 @@ func Load(configFile string) (*Config, error) {
7377
return nil, err
7478
}
7579

80+
// Validate tools configuration
81+
if err := cfg.Tools.Validate(); err != nil {
82+
return nil, fmt.Errorf("tools validation failed: %w", err)
83+
}
84+
7685
return &cfg, nil
7786
}
7887

0 commit comments

Comments
 (0)