-
Notifications
You must be signed in to change notification settings - Fork 85
mcp/examples: add PostgreSQL MCP server example #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks for this large contribution. It's a lot of work, and we appreciate that. It's cool that you have a complete implementation, with a Makefile, shell scripts, Dockerfile, and so on. This is definitely worth living somewhere. I'm just not sure it should live in this repo. There is a lot of code to maintain. What if we get a bug report against the Dockerfile or docker compose config? Or some bug about a runtime failure in a particular installation? I don't know if the maintainers of this repo are up to that sort of commitment. We're going to think about this and get back to you. |
Thanks a lot for your nice words. |
The modelcontextprotocol/servers repo is not going to happen. Here's what we'd like to do:
One concern is that the additional non-Go code is a maintenance burden for us. We are also concerned about security. You can leave all the other code here for now if it helps you test my suggested changes. Thanks again for this great piece of work! |
Thank a lot for your review. I did learn a lot from it. I have addressed the comments. Please take another look when you have a chance. As for the all other code, do you mean I can keep |
Yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Proceed with removing the non-Go files.
Leave the README as it is for your own repo, but for this repo, leave an edited version that links to your repo.
if trimmedPath != "" { | ||
pathParts = strings.Split(trimmedPath, "/") | ||
// Filter out empty parts that might result from consecutive slashes | ||
var filteredParts []string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use slices.DeleteFunc.
{ | ||
name: "edge case - table name with special characters", | ||
resourceURI: "postgres://localhost:5432/testdb/test-table_123/schema", | ||
expectedTable: "test-table_123", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test with "///" to test removal of empty parts.
Add standalone PostgreSQL MCP server example with development environment and tooling. This implementation provides read-only database access, schema introspection, and query capabilities while maintaining clean dependency separation from the main SDK.
Motivation and Context
This is part of #33. This PR adds example of implementing mcp on PostgreSQL from https://modelcontextprotocol.io/examples.
The PR provides a production-ready PostgreSQL MCP server example with proper deployment options, testing, and development tooling.
How Has This Been Tested?
Breaking Changes
Types of changes
Checklist
Additional context
Architecture Decisions
examples/postgres/go.mod
for this exampleFiles Added
main.go
- PostgreSQL MCP server implementation with schema introspection and query toolsmain_test.go
- Comprehensive test suite with mock database testinggo.mod/go.sum
- Independent module definition with local SDK referenceDockerfile
- Multi-stage build for production deploymentdocker-compose.yml
- Complete development environment with PostgreSQLinit.sql
- Sample database schema and data for testingMakefile
- Build automation and development workflowdemo.sh
- Interactive demonstration scriptREADME.md
- Complete documentation following Python server format.env.example
- Configuration template.gitignore
- Proper exclusions for Go and Docker artifactsDevelopment Experience
make dev
sets up complete environmentMCP Features Implemented
postgres://host/table/schema
This implementation serves as a reference for building production MCP servers while maintaining clean project architecture.