Skip to content

Commit 2897bf5

Browse files
committed
fix: 二次验证修复5篇文档16处确认错误
04-MCP: 4个Python包改用uvx、PostgreSQL连接字符串改args、工具列表修正、GitHub环境变量名修正 05-Hooks: Hook类型数量8→15补充6种新类型、决策值新旧API说明 08-SDK: Haiku模型ID格式修正、can_use_tool签名修正、TS类型名修正 09-综合实战: permissions结构改为扁平格式、deniedTools→disallowedTools、删除虚构模型 10-企业实战: 删除编造的import语法改为正确配置共享方式
1 parent 0f9fb72 commit 2897bf5

5 files changed

Lines changed: 295 additions & 148 deletions

File tree

docs/claude-code/04-MCP集成完整指南.md

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -537,21 +537,21 @@ claude mcp add --scope user my-server npx -y xxx
537537
**Windows(PowerShell 7):**
538538
```powershell
539539
# 永久设置环境变量
540-
[System.Environment]::SetEnvironmentVariable('GITHUB_TOKEN', 'ghp_你的Token', 'User')
540+
[System.Environment]::SetEnvironmentVariable('GITHUB_PERSONAL_ACCESS_TOKEN', 'ghp_你的Token', 'User')
541541
542542
# 验证
543-
$env:GITHUB_TOKEN
543+
$env:GITHUB_PERSONAL_ACCESS_TOKEN
544544
# 应显示你的Token
545545
```
546546

547547
**macOS/Linux:**
548548
```bash
549549
# 添加到shell配置文件
550-
echo 'export GITHUB_TOKEN="ghp_你的Token"' >> ~/.zshrc
550+
echo 'export GITHUB_PERSONAL_ACCESS_TOKEN="ghp_你的Token"' >> ~/.zshrc
551551
source ~/.zshrc
552552

553553
# 验证
554-
echo $GITHUB_TOKEN
554+
echo $GITHUB_PERSONAL_ACCESS_TOKEN
555555
```
556556

557557
**步骤3:添加MCP配置**
@@ -565,14 +565,14 @@ echo $GITHUB_TOKEN
565565
"command": "npx",
566566
"args": ["-y", "@modelcontextprotocol/server-github"],
567567
"env": {
568-
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
568+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
569569
}
570570
}
571571
}
572572
}
573573
```
574574

575-
> 💡 **说明**`${GITHUB_TOKEN}` 会自动读取环境变量,不用把Token直接写在配置文件里
575+
> 💡 **说明**`${GITHUB_PERSONAL_ACCESS_TOKEN}` 会自动读取环境变量,不用把Token直接写在配置文件里
576576
577577
**步骤4:验证配置**
578578

@@ -612,15 +612,15 @@ claude
612612
{
613613
"mcpServers": {
614614
"sqlite": {
615-
"command": "npx",
616-
"args": ["-y", "@modelcontextprotocol/server-sqlite", "./data/app.db"],
615+
"command": "uvx",
616+
"args": ["mcp-server-sqlite", "--db-path", "./data/app.db"],
617617
"env": {}
618618
}
619619
}
620620
}
621621
```
622622

623-
> 💡 **说明**最后一个参数是数据库文件路径,不存在会自动创建
623+
> 💡 **说明**最后的参数是数据库文件路径,不存在会自动创建。SQLite MCP是Python包,需要用 `uvx` 而非 `npx`
624624
625625
**提供的工具**
626626

@@ -652,10 +652,7 @@ claude
652652
"mcpServers": {
653653
"postgres": {
654654
"command": "npx",
655-
"args": ["-y", "@modelcontextprotocol/server-postgres"],
656-
"env": {
657-
"POSTGRES_CONNECTION_STRING": "postgresql://user:password@localhost:5432/database"
658-
}
655+
"args": ["-y", "@modelcontextprotocol/server-postgres", "postgresql://user:password@localhost:5432/database"]
659656
}
660657
}
661658
}
@@ -664,16 +661,15 @@ claude
664661
> ⚠️ **安全建议**
665662
> - 使用只读数据库用户
666663
> - 不要在配置文件中硬编码密码
667-
> - 使用环境变量`"${POSTGRES_CONNECTION_STRING}"`
664+
> - 连接字符串通过 `args` 传递,可使用环境变量替代硬编码`"postgresql://${PGUSER}:${PGPASSWORD}@localhost:5432/database"`
668665
669666
**提供的工具**
670667

671668
| 工具名 | 功能 | 参数 |
672669
|--------|------|------|
673670
| `query` | 执行SQL查询 | sql |
674-
| `list_schemas` | 列出模式 | - |
675-
| `list_tables` | 列出表 | schema |
676-
| `describe_table` | 获取表结构 | schema, table |
671+
672+
> 💡 **说明**`query` 是唯一的Tool。表结构信息(schemas、tables、columns)通过MCP的Resources机制自动暴露,无需手动调用工具即可获取
677673
678674
### 3.4 三作用域配置体系
679675

@@ -707,9 +703,9 @@ Local > Project > User
707703
假设三个作用域都配置了 `github` 服务器:
708704

709705
```
710-
User作用域:GITHUB_TOKEN = "user-token"
711-
Project作用域:GITHUB_TOKEN = "${GITHUB_TOKEN}"
712-
Local作用域:GITHUB_TOKEN = "local-override-token"
706+
User作用域:GITHUB_PERSONAL_ACCESS_TOKEN = "user-token"
707+
Project作用域:GITHUB_PERSONAL_ACCESS_TOKEN = "${GITHUB_PERSONAL_ACCESS_TOKEN}"
708+
Local作用域:GITHUB_PERSONAL_ACCESS_TOKEN = "local-override-token"
713709
714710
最终生效:Local作用域的配置(local-override-token)
715711
```
@@ -736,7 +732,7 @@ Local作用域:GITHUB_TOKEN = "local-override-token"
736732
"command": "npx",
737733
"args": ["-y", "@modelcontextprotocol/server-github"],
738734
"env": {
739-
"GITHUB_TOKEN": "ghp_xxxx_local_override"
735+
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxxx_local_override"
740736
}
741737
}
742738
}
@@ -753,7 +749,7 @@ Local作用域:GITHUB_TOKEN = "local-override-token"
753749
"command": "npx",
754750
"args": ["-y", "@modelcontextprotocol/server-github"],
755751
"env": {
756-
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
752+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
757753
}
758754
}
759755
}
@@ -888,8 +884,8 @@ claude mcp add --transport http my-remote-server https://your-server.com/mcp
888884
{
889885
"mcpServers": {
890886
"fetch": {
891-
"command": "npx",
892-
"args": ["-y", "@modelcontextprotocol/server-fetch"],
887+
"command": "uvx",
888+
"args": ["mcp-server-fetch"],
893889
"env": {}
894890
}
895891
}
@@ -948,12 +944,12 @@ claude mcp add --transport http my-remote-server https://your-server.com/mcp
948944
"command": "npx",
949945
"args": ["-y", "@modelcontextprotocol/server-github"],
950946
"env": {
951-
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
947+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
952948
}
953949
},
954950
"sqlite": {
955-
"command": "npx",
956-
"args": ["-y", "@modelcontextprotocol/server-sqlite", "./data/app.db"],
951+
"command": "uvx",
952+
"args": ["mcp-server-sqlite", "--db-path", "./data/app.db"],
957953
"env": {}
958954
},
959955
"context7": {
@@ -974,8 +970,8 @@ claude mcp add --transport http my-remote-server https://your-server.com/mcp
974970
"env": {}
975971
},
976972
"fetch": {
977-
"command": "npx",
978-
"args": ["-y", "@modelcontextprotocol/server-fetch"],
973+
"command": "uvx",
974+
"args": ["mcp-server-fetch"],
979975
"env": {}
980976
}
981977
}
@@ -1858,7 +1854,7 @@ cat .mcp.json | jq .
18581854

18591855
**错误信息示例**
18601856
```
1861-
Error: GITHUB_TOKEN is required
1857+
Error: GITHUB_PERSONAL_ACCESS_TOKEN is required
18621858
Error: Missing required environment variable
18631859
```
18641860

@@ -1867,23 +1863,23 @@ Error: Missing required environment variable
18671863
**Windows(PowerShell):**
18681864
```powershell
18691865
# 检查环境变量
1870-
$env:GITHUB_TOKEN
1866+
$env:GITHUB_PERSONAL_ACCESS_TOKEN
18711867
# 如果为空,说明未设置
18721868
18731869
# 设置环境变量
1874-
[System.Environment]::SetEnvironmentVariable('GITHUB_TOKEN', 'your-token', 'User')
1870+
[System.Environment]::SetEnvironmentVariable('GITHUB_PERSONAL_ACCESS_TOKEN', 'your-token', 'User')
18751871
18761872
# 重启终端后验证
1877-
$env:GITHUB_TOKEN
1873+
$env:GITHUB_PERSONAL_ACCESS_TOKEN
18781874
```
18791875

18801876
**macOS/Linux:**
18811877
```bash
18821878
# 检查环境变量
1883-
echo $GITHUB_TOKEN
1879+
echo $GITHUB_PERSONAL_ACCESS_TOKEN
18841880

18851881
# 如果为空,添加到shell配置
1886-
echo 'export GITHUB_TOKEN="your-token"' >> ~/.zshrc
1882+
echo 'export GITHUB_PERSONAL_ACCESS_TOKEN="your-token"' >> ~/.zshrc
18871883
source ~/.zshrc
18881884
```
18891885

@@ -2016,12 +2012,12 @@ del %USERPROFILE%\.claude.json
20162012
{
20172013
"mcpServers": {
20182014
"sqlite-app": {
2019-
"command": "npx",
2020-
"args": ["-y", "@modelcontextprotocol/server-sqlite", "./app.db"]
2015+
"command": "uvx",
2016+
"args": ["mcp-server-sqlite", "--db-path", "./app.db"]
20212017
},
20222018
"sqlite-analytics": {
2023-
"command": "npx",
2024-
"args": ["-y", "@modelcontextprotocol/server-sqlite", "./analytics.db"]
2019+
"command": "uvx",
2020+
"args": ["mcp-server-sqlite", "--db-path", "./analytics.db"]
20252021
}
20262022
}
20272023
}
@@ -2193,12 +2189,12 @@ npm publish --access public
21932189
"command": "npx",
21942190
"args": ["-y", "@modelcontextprotocol/server-github"],
21952191
"env": {
2196-
"GITHUB_TOKEN": "${GITHUB_TOKEN}"
2192+
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_PERSONAL_ACCESS_TOKEN}"
21972193
}
21982194
},
21992195
"sqlite": {
2200-
"command": "npx",
2201-
"args": ["-y", "@modelcontextprotocol/server-sqlite", "./data/app.db"],
2196+
"command": "uvx",
2197+
"args": ["mcp-server-sqlite", "--db-path", "./data/app.db"],
22022198
"env": {}
22032199
},
22042200
"context7": {
@@ -2219,8 +2215,8 @@ npm publish --access public
22192215
"env": {}
22202216
},
22212217
"fetch": {
2222-
"command": "npx",
2223-
"args": ["-y", "@modelcontextprotocol/server-fetch"],
2218+
"command": "uvx",
2219+
"args": ["mcp-server-fetch"],
22242220
"env": {}
22252221
},
22262222
"sequential-thinking": {
@@ -2256,12 +2252,12 @@ npm publish --access public
22562252
| Filesystem | `@modelcontextprotocol/server-filesystem` | 文件系统操作 ||
22572253
| GitHub | `@modelcontextprotocol/server-github` | GitHub仓库管理 ||
22582254
| GitLab | `@modelcontextprotocol/server-gitlab` | GitLab仓库管理 | |
2259-
| Git | `@modelcontextprotocol/server-git` | 本地Git操作 | |
2260-
| SQLite | `@modelcontextprotocol/server-sqlite` | SQLite数据库 ||
2255+
| Git | `mcp-server-git`(Python/uvx) | 本地Git操作 | |
2256+
| SQLite | `mcp-server-sqlite`(Python/uvx) | SQLite数据库 ||
22612257
| PostgreSQL | `@modelcontextprotocol/server-postgres` | PostgreSQL数据库 | |
22622258
| Memory | `@modelcontextprotocol/server-memory` | 持久化记忆 | |
2263-
| Fetch | `@modelcontextprotocol/server-fetch` | 网页获取 | |
2264-
| Time | `@modelcontextprotocol/server-time` | 时间服务 | |
2259+
| Fetch | `mcp-server-fetch`(Python/uvx) | 网页获取 | |
2260+
| Time | `mcp-server-time`(Python/uvx) | 时间服务 | |
22652261
| Sequential Thinking | `@modelcontextprotocol/server-sequential-thinking` | 顺序思考 | |
22662262
| Puppeteer | `@modelcontextprotocol/server-puppeteer` | 浏览器自动化 | |
22672263
| Brave Search | `@modelcontextprotocol/server-brave-search` | 网页搜索 ||

0 commit comments

Comments
 (0)