{"_id":"enhanced-postgres-mcp-server","_rev":"2-cf24bc88a461e4dd331b542b498d9629","name":"enhanced-postgres-mcp-server","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"enhanced-postgres-mcp-server","version":"1.0.0","keywords":["mcp","model-context-protocol","claude","anthropic","postgres","postgresql","database","llm"],"author":{"name":"Gareth Cottrell"},"license":"MIT","_id":"enhanced-postgres-mcp-server@1.0.0","maintainers":[{"name":"jlzan1314","email":"jlzan1314@qq.com"}],"contributors":[{"url":"https://anthropic.com","name":"Anthropic, PBC"}],"homepage":"https://github.com/garethcottrell/enhanced-postgres-mcp-server","bugs":{"url":"https://github.com/garethcottrell/enhanced-postgres-mcp-server/issues"},"bin":{"enhanced-postgres-mcp":"dist/index.js"},"dist":{"shasum":"17f528641f68553888020b497eda3fc7ef88cefd","tarball":"https://registry.npmjs.org/enhanced-postgres-mcp-server/-/enhanced-postgres-mcp-server-1.0.0.tgz","fileCount":7,"integrity":"sha512-ruI9i1MY7hIGkO8rVT7HyDRZNHYbyBzkENfNX4aweFXcT+xZDSXwfEQNS1l9y2M7ROs4aJaqrYY+PdqNITJ4sw==","signatures":[{"sig":"MEUCIDX1EF/nbJZmNxlTugECX1ek3jfYXzuNgLfnA6lQq6tFAiEAyJyYX9YdDjHj90rWs0BLms6gtx9Rxba6AZaXocfs2AU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":48159},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","engines":{"node":">=18.0.0"},"gitHead":"f7443c95b33da49393ed15e9f27796248e72dedb","scripts":{"build":"tsc","start":"node dist/index.js","watch":"tsc --watch","prepare":"npm run build","docker:run":"docker run -i --rm mcp/postgres","docker:build":"docker build -t mcp/postgres -f Dockerfile ."},"_npmUser":{"name":"jlzan1314","email":"jlzan1314@qq.com"},"_npmVersion":"11.4.2","description":"Enhanced PostgreSQL MCP server with read and write capabilities. Based on @modelcontextprotocol/server-postgres by Anthropic.","directories":{},"_nodeVersion":"20.19.2","dependencies":{"pg":"^8.13.0","@modelcontextprotocol/sdk":"1.0.1"},"_hasShrinkwrap":false,"devDependencies":{"shx":"^0.3.4","@types/pg":"^8.11.10","typescript":"^5.6.2","@types/node":"^20.11.5"},"_npmOperationalInternal":{"tmp":"tmp/enhanced-postgres-mcp-server_1.0.0_1752890042611_0.05804555067533901","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"enhanced-postgres-mcp-server","version":"1.0.1","description":"Enhanced PostgreSQL MCP server with read and write capabilities. Based on @modelcontextprotocol/server-postgres by Anthropic.","license":"MIT","author":{"name":"Gareth Cottrell"},"contributors":[{"name":"Anthropic, PBC","url":"https://anthropic.com"}],"homepage":"https://github.com/garethcottrell/enhanced-postgres-mcp-server","bugs":{"url":"https://github.com/garethcottrell/enhanced-postgres-mcp-server/issues"},"type":"module","main":"dist/index.js","bin":{"enhanced-postgres-mcp":"dist/index.js"},"scripts":{"build":"tsc","prepare":"npm run build","watch":"tsc --watch","start":"node dist/index.js","test":"jest","test:watch":"jest --watch","test:coverage":"jest --coverage","test:basic":"npx jest tests/basic.test.ts","test:sql":"npx jest tests/sql-builder.test.ts","test:working":"node scripts/test-runner.cjs working","test:all":"node scripts/test-runner.cjs all","test:mcp":"npx jest tests/mcp-sql.test.ts","test:service":"npx jest tests/mcp-service-simple.test.ts","test:real-db":"npx jest tests/real-postgres.test.ts","test:mcp-real":"npx jest tests/mcp-real-postgres.test.ts","test:real-all":"npx jest tests/real-postgres.test.ts tests/mcp-real-postgres.test.ts","test:stable":"npx jest tests/basic.test.ts tests/sql-builder.test.ts tests/mcp-sql.test.ts tests/mcp-service-simple.test.ts","test:complete":"npx jest tests/basic.test.ts tests/sql-builder.test.ts tests/mcp-sql.test.ts tests/mcp-service-simple.test.ts tests/real-postgres.test.ts tests/mcp-real-postgres.test.ts","docker:build":"docker build -t mcp/postgres -f Dockerfile .","docker:run":"docker run -i --rm mcp/postgres"},"dependencies":{"@modelcontextprotocol/sdk":"1.0.1","pg":"^8.13.0"},"devDependencies":{"@types/node":"^20.11.5","@types/pg":"^8.11.10","@types/jest":"^29.5.12","jest":"^29.7.0","ts-jest":"^29.1.2","pg-mem":"^2.8.1","shx":"^0.3.4","typescript":"^5.6.2"},"engines":{"node":">=18.0.0"},"keywords":["mcp","model-context-protocol","claude","anthropic","postgres","postgresql","database","llm"],"_id":"enhanced-postgres-mcp-server@1.0.1","gitHead":"a2007f8448eef536cf2d0dc688cc9ab836f0c968","types":"./dist/index.d.ts","_nodeVersion":"20.19.2","_npmVersion":"11.4.2","dist":{"integrity":"sha512-tw7GJbrgdwrNl0ZEYuytNfEwNBNqplpGCwMN3mJ3okqEl9xm3c1Dft/5N38YwUxmkAQbK86eiA6Fq95dR/2f9A==","shasum":"3d7a3549f3a0b7cac16747752327131c276a48be","tarball":"https://registry.npmjs.org/enhanced-postgres-mcp-server/-/enhanced-postgres-mcp-server-1.0.1.tgz","fileCount":51,"unpackedSize":329440,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQC/HiM7y8qRHgsGag71TWfsB5pgmcAHnZL7PA4cXPuGVgIgBUkjeqG53JUr7iG/nK3XZ5x/LYnVR9mpfo+M+KaqB0E="}]},"_npmUser":{"name":"jlzan1314","email":"jlzan1314@qq.com"},"directories":{},"maintainers":[{"name":"jlzan1314","email":"jlzan1314@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/enhanced-postgres-mcp-server_1.0.1_1752897386954_0.29429800010209206"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-19T01:54:02.610Z","modified":"2025-07-19T03:56:27.447Z","1.0.0":"2025-07-19T01:54:02.897Z","1.0.1":"2025-07-19T03:56:27.230Z"},"bugs":{"url":"https://github.com/garethcottrell/enhanced-postgres-mcp-server/issues"},"author":{"name":"Gareth Cottrell"},"license":"MIT","homepage":"https://github.com/garethcottrell/enhanced-postgres-mcp-server","keywords":["mcp","model-context-protocol","claude","anthropic","postgres","postgresql","database","llm"],"description":"Enhanced PostgreSQL MCP server with read and write capabilities. Based on @modelcontextprotocol/server-postgres by Anthropic.","contributors":[{"name":"Anthropic, PBC","url":"https://anthropic.com"}],"maintainers":[{"name":"jlzan1314","email":"jlzan1314@qq.com"}],"readme":"# PostgreSQL MCP 服务器（增强版）\r\n\r\n一个模型上下文协议服务器，提供对PostgreSQL数据库的读写访问。该服务器使LLM能够检查数据库模式、执行查询、修改数据以及创建/修改数据库模式对象。\r\n\r\n> **注意：** 这是Anthropic原始[PostgreSQL MCP服务器](https://github.com/modelcontextprotocol/servers/tree/main/src/postgres)的增强版本。原始服务器仅提供只读访问，而此增强版本添加了写入功能和模式管理。\r\n\r\n## 组件\r\n\r\n### 工具\r\n\r\n#### 数据查询\r\n- **query**\r\n  - 对连接的数据库执行只读SQL查询\r\n  - 输入：`sql`（字符串）：要执行的SQL查询\r\n  - 所有查询都在只读事务中执行\r\n\r\n#### 数据修改\r\n- **execute**\r\n  - 执行修改数据的SQL语句（INSERT、UPDATE、DELETE）\r\n  - 输入：`sql`（字符串）：要执行的SQL语句\r\n  - 在具有适当COMMIT/ROLLBACK处理的事务中执行\r\n\r\n- **insert**\r\n  - 向表中插入新记录\r\n  - 输入：\r\n    - `table`（字符串）：表名\r\n    - `data`（对象）：键值对，其中键是列名，值是要插入的数据\r\n\r\n- **update**\r\n  - 更新表中的记录\r\n  - 输入：\r\n    - `table`（字符串）：表名\r\n    - `data`（对象）：要更新字段的键值对\r\n    - `where`（字符串）：用于标识要更新记录的WHERE条件\r\n\r\n- **delete**\r\n  - 从表中删除记录\r\n  - 输入：\r\n    - `table`（字符串）：表名\r\n    - `where`（字符串）：用于标识要删除记录的WHERE条件\r\n\r\n#### 模式管理\r\n- **createTable**\r\n  - 创建具有指定列和约束的新表\r\n  - 输入：\r\n    - `tableName`（字符串）：表名\r\n    - `columns`（数组）：列定义数组，包含名称、类型和可选约束\r\n    - `constraints`（数组）：可选的表级约束数组\r\n\r\n- **createFunction**\r\n  - 创建PostgreSQL函数/过程\r\n  - 输入：\r\n    - `name`（字符串）：函数名\r\n    - `parameters`（字符串）：函数参数\r\n    - `returnType`（字符串）：返回类型\r\n    - `language`（字符串）：语言（plpgsql、sql等）\r\n    - `body`（字符串）：函数体\r\n    - `options`（字符串）：可选的附加函数选项\r\n\r\n- **createTrigger**\r\n  - 在表上创建触发器\r\n  - 输入：\r\n    - `name`（字符串）：触发器名称\r\n    - `tableName`（字符串）：应用触发器的表\r\n    - `functionName`（字符串）：要调用的函数\r\n    - `when`（字符串）：BEFORE、AFTER或INSTEAD OF\r\n    - `events`（数组）：事件数组（INSERT、UPDATE、DELETE）\r\n    - `forEach`（字符串）：ROW或STATEMENT\r\n    - `condition`（字符串）：可选的WHEN条件\r\n\r\n- **createIndex**\r\n  - 在表上创建索引\r\n  - 输入：\r\n    - `tableName`（字符串）：表名\r\n    - `indexName`（字符串）：索引名\r\n    - `columns`（数组）：要索引的列\r\n    - `unique`（布尔值）：索引是否唯一\r\n    - `type`（字符串）：可选的索引类型（BTREE、HASH、GIN、GIST等）\r\n    - `where`（字符串）：可选条件\r\n\r\n- **alterTable**\r\n  - 修改表结构\r\n  - 输入：\r\n    - `tableName`（字符串）：表名\r\n    - `operation`（字符串）：操作（ADD COLUMN、DROP COLUMN等）\r\n    - `details`（字符串）：操作详情\r\n\r\n### 资源\r\n\r\n服务器为数据库中的每个表提供模式信息：\r\n\r\n- **表模式**（`postgres://<host>/<table>/schema`）\r\n  - 每个表的JSON模式信息\r\n  - 包括列名和数据类型\r\n  - 从数据库元数据自动发现\r\n\r\n## 在Claude Desktop中使用\r\n\r\n要在Claude Desktop应用程序中使用此服务器，请将以下配置添加到`claude_desktop_config.json`的\"mcpServers\"部分：\r\n\r\n### Docker\r\n* docker镜像需要自己编译\r\n* 在macOS上运行docker时，如果服务器在主机网络上运行（例如localhost），请使用host.docker.internal\r\n* 用户名/密码可以通过`postgresql://user:password@host:port/db-name`添加到postgresql url中\r\n* 如果需要绕过SSL证书验证，请添加`?sslmode=no-verify`\r\n\r\n### NPM包（推荐）\r\n\r\n```json\r\n{\r\n  \"mcpServers\": {\r\n    \"postgres\": {\r\n      \"command\": \"npx\",\r\n      \"args\": [\r\n        \"-y\",\r\n        \"enhanced-postgres-mcp-server\",\r\n        \"postgresql://username:password@localhost:5432/mydb\"\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n**连接字符串格式说明：**\r\n- `postgresql://username:password@localhost:5432/mydb` - 包含用户名和密码的完整格式\r\n- `postgresql://localhost/mydb` - 使用默认用户的简化格式\r\n- `postgresql://postgres:mypassword@localhost:5432/mydatabase` - 示例：用户名postgres，密码mypassword，数据库mydatabase\r\n\r\n**SSL连接支持：**\r\n服务器支持多种SSL配置方式，可以根据您的数据库环境选择合适的方法：\r\n\r\n1. **URL参数方式（推荐）：**\r\n   - `postgresql://username:password@host:5432/db?ssl=true` - 启用SSL连接\r\n   - `postgresql://username:password@host:5432/db?sslmode=require` - 要求SSL连接\r\n   - `postgresql://username:password@host:5432/db?sslmode=no-verify` - SSL连接但跳过证书验证\r\n\r\n2. **环境变量方式：**\r\n   - 设置 `POSTGRES_SSL=true` 环境变量来启用SSL\r\n   - 设置 `POSTGRES_SSL_FORCE=true` 强制启用SSL（覆盖URL设置）\r\n   - 设置 `POSTGRES_SSL_REJECT_UNAUTHORIZED=true` 启用严格的证书验证（默认为false）\r\n\r\n3. **自动SSL检测：**\r\n   - 远程连接（非localhost/127.0.0.1）会自动启用SSL\r\n   - 本地连接默认不使用SSL，除非明确指定\r\n\r\n**SSL配置示例：**\r\n```json\r\n{\r\n  \"mcpServers\": {\r\n    \"postgres-ssl\": {\r\n      \"command\": \"npx\",\r\n      \"args\": [\r\n        \"-y\",\r\n        \"enhanced-postgres-mcp-server\",\r\n        \"postgresql://username:password@remote-db.example.com:5432/mydb?ssl=true\"\r\n      ]\r\n    }\r\n  }\r\n}\r\n```\r\n\r\n**注意事项：**\r\n- 对于自签名证书或开发环境，建议使用 `?sslmode=no-verify` 或设置 `POSTGRES_SSL_REJECT_UNAUTHORIZED=false`\r\n- 生产环境建议使用有效的SSL证书并启用证书验证\r\n- 如果数据库要求SSL连接，请确保在连接字符串中包含相应的SSL参数\r\n\r\n将连接字符串中的参数替换为您的实际数据库配置。\r\n\r\n## 使用示例\r\n\r\n### 查询数据\r\n```\r\n/query SELECT * FROM postgres_log LIMIT 5\r\n```\r\n\r\n### 插入数据\r\n```\r\n/insert table=\"users\", data={\"name\": \"张三\", \"email\": \"zhangsan@example.com\"}\r\n```\r\n\r\n### 更新数据\r\n```\r\n/update table=\"users\", data={\"status\": \"inactive\"}, where=\"id='123'\"\r\n```\r\n\r\n### 创建表\r\n```\r\n/createTable tableName=\"tasks\", columns=[\r\n  {\"name\": \"id\", \"type\": \"SERIAL\", \"constraints\": \"PRIMARY KEY\"}, \r\n  {\"name\": \"title\", \"type\": \"VARCHAR(100)\", \"constraints\": \"NOT NULL\"},\r\n  {\"name\": \"created_at\", \"type\": \"TIMESTAMP\", \"constraints\": \"DEFAULT CURRENT_TIMESTAMP\"}\r\n]\r\n```\r\n\r\n### 创建函数和触发器\r\n```\r\n/createFunction name=\"update_timestamp\", parameters=\"\", returnType=\"TRIGGER\", language=\"plpgsql\", body=\"BEGIN NEW.updated_at = NOW(); RETURN NEW; END;\"\r\n\r\n/createTrigger name=\"set_timestamp\", tableName=\"tasks\", functionName=\"update_timestamp\", when=\"BEFORE\", events=[\"UPDATE\"], forEach=\"ROW\"\r\n```\r\n\r\n## 构建\r\n\r\nDocker：\r\n\r\n```sh\r\ndocker build -t mcp/postgres -f Dockerfile . \r\n```\r\n\r\n## 安全考虑\r\n\r\n1. 所有数据修改操作都使用具有适当COMMIT/ROLLBACK处理的事务\r\n2. 每个操作都返回执行的SQL以确保透明度\r\n3. 服务器对插入/更新操作使用参数化查询以防止SQL注入\r\n\r\n## 许可证\r\n\r\n此MCP服务器根据MIT许可证授权。这意味着您可以自由使用、修改和分发软件，但需遵守MIT许可证的条款和条件。有关更多详细信息，请参阅项目存储库中的LICENSE文件。\r\n","readmeFilename":"README.md"}