Skip to content

fix: resolve MCP server availability discrepancy issue#1339

Open
atxtechbro wants to merge 1 commit intomainfrom
issue-1338
Open

fix: resolve MCP server availability discrepancy issue#1339
atxtechbro wants to merge 1 commit intomainfrom
issue-1338

Conversation

@atxtechbro
Copy link
Copy Markdown
Owner

Summary

Fixes the issue where Claude Code incorrectly reports having access to MCP servers that aren't actually connected.

Closes #1338

Problem

  • Claude Code's internal tool approval list included MCP servers (github-write, git) that weren't configured
  • After removing servers from mcp/mcp.json and running setup.sh, Claude still reported them as available
  • This was due to cached MCP server information not being cleared

Solution

  1. Documentation: Created comprehensive guide explaining which MCP servers are actually available vs. merely approved
  2. Diagnostic Tool: Added claude-mcp-diagnostic to help users troubleshoot MCP server availability issues
  3. Cache Clearing: Modified setup.sh to automatically clear Claude Code's cache when MCP configuration changes
  4. Cross-references: Updated existing MCP documentation to reference the new availability guide

Changes

  • New: bin/claude-mcp-diagnostic - Diagnostic tool for MCP server issues
  • New: docs/mcp-server-availability.md - Comprehensive guide on server availability vs. approval list
  • Modified: setup.sh - Now clears ~/.claude/statsig/* cache when updating MCP config
  • Modified: docs/mcp-environment.md - Added reference to availability guide
  • Modified: docs/mcp-client-integration.md - Added important note about server availability

Testing

  1. Run setup.sh to apply the changes
  2. Use claude-mcp-diagnostic to verify MCP server configuration
  3. Run claude mcp list to confirm only configured servers appear
  4. Check that cache is cleared: ls ~/.claude/statsig/ should be empty after setup

Impact

  • Users will get accurate information about which MCP servers are available
  • No more confusion between approved and actually connected servers
  • Automatic cache clearing prevents stale server information

Closes #1338

Problem:
- Claude Code reported having access to MCP servers (github-write, git) that weren't actually connected
- These servers appeared in internal tool approval list but weren't in mcp/mcp.json
- After removing servers and running setup.sh, Claude still thought they were available due to cached information

Solution:
1. Added documentation clarifying which MCP servers are actually available vs approved
2. Created diagnostic tool to help users troubleshoot MCP server availability
3. Updated setup.sh to clear Claude Code's cache when MCP config changes
4. Added cross-references in existing MCP documentation

Changes:
- New: bin/claude-mcp-diagnostic - diagnostic tool for MCP issues
- New: docs/mcp-server-availability.md - comprehensive guide on server availability
- Modified: setup.sh - clears ~/.claude/statsig/* cache on MCP config changes
- Modified: docs/mcp-*.md - added references to new availability guide

This ensures Claude Code correctly reports MCP server availability after configuration changes.
@amazon-q-developer
Copy link
Copy Markdown
Contributor

Code review in progress. Analyzing for code quality issues and best practices. Detailed findings will be posted upon completion.

Using Amazon Q Developer for GitHub

Amazon Q Developer1 is an AI-powered assistant that integrates directly into your GitHub workflow, enhancing your development process with intelligent features for code development, review, and transformation.

Slash Commands

Command Description
/q <message> Chat with the agent to ask questions or request revisions
/q review Requests an Amazon Q powered code review
/q help Displays usage information

Features

Agentic Chat
Enables interactive conversation with Amazon Q to ask questions about the pull request or request specific revisions. Use /q <message> in comment threads or the review body to engage with the agent directly.

Code Review
Analyzes pull requests for code quality, potential issues, and security concerns. Provides feedback and suggested fixes. Automatically triggered on new or reopened PRs (can be disabled for AWS registered installations), or manually with /q review slash command in a comment.

Customization

You can create project-specific rules for Amazon Q Developer to follow:

  1. Create a .amazonq/rules folder in your project root.
  2. Add Markdown files in this folder to define rules (e.g., cdk-rules.md).
  3. Write detailed prompts in these files, such as coding standards or best practices.
  4. Amazon Q Developer will automatically use these rules when generating code or providing assistance.

Example rule:

All Amazon S3 buckets must have encryption enabled, enforce SSL, and block public access.
All Amazon DynamoDB Streams tables must have encryption enabled.
All Amazon SNS topics must have encryption enabled and enforce SSL.
All Amazon SNS queues must enforce SSL.

Feedback

To provide feedback on Amazon Q Developer, create an issue in the Amazon Q Developer public repository.

For more detailed information, visit the Amazon Q for GitHub documentation.

Footnotes

  1. Amazon Q Developer uses generative AI. You may need to verify generated code before using it in your environment. See the AWS Responsible AI Policy.

Copy link
Copy Markdown
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall Assessment

This PR effectively addresses the MCP server availability discrepancy issue with a comprehensive solution that includes diagnostic tooling, clear documentation, and automatic cache management. The approach is well-structured and addresses the root cause of the problem.

Key Strengths

  • Comprehensive diagnostic tool: The claude-mcp-diagnostic script provides valuable troubleshooting capabilities for users experiencing MCP server issues
  • Clear documentation: The new mcp-server-availability.md guide clearly explains the difference between approved and actually available servers
  • Automatic cache clearing: The setup.sh modification prevents stale cache issues by automatically clearing Claude Code's cache when MCP configuration changes
  • Cross-references: Good integration with existing documentation through appropriate cross-references

Critical Changes Requested

  1. File termination issues: Both bin/claude-mcp-diagnostic and docs/mcp-server-availability.md lack proper newline termination, which violates POSIX standards
  2. Enhanced error handling: The cache clearing logic in setup.sh could be more robust with better empty directory handling
  3. Improved diagnostics: The MCP server listing test could capture and display actual output for better troubleshooting

Minor Improvements

  • Version extraction regex could be more flexible for different version formats
  • JSON configuration example needs clarification about environment variable substitution
  • Cache clearing recommendations could include safety checks

The solution effectively resolves the reported issue and provides users with the tools needed to understand and troubleshoot MCP server availability. With the suggested improvements, this will be a solid addition to the dotfiles repository.

echo -e " - Try restarting your terminal session"
echo -e " - Run: ${GREEN}claude logout && claude login${NC}"

echo -e "\n${BLUE}${DIVIDER}${NC}" No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script lacks a proper file termination with a newline character, which could cause issues on some systems and violates POSIX standards. Files should end with a newline character.

# 1. Check Claude Code installation
echo -e "${YELLOW}1. Claude Code Installation:${NC}"
if command -v claude &>/dev/null; then
CLAUDE_VERSION=$(claude --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "unknown")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern for version extraction could be more robust. The current pattern [0-9]+\.[0-9]+\.[0-9]+ might miss pre-release versions or versions with additional components like 1.2.3-beta or 1.2.3.4. Consider using a more flexible pattern to handle various version formats.

Comment on lines +61 to +66
# 4. Test MCP server listing
echo -e "${YELLOW}4. Claude MCP Server List:${NC}"
echo "Running: claude mcp list"
if claude mcp list 2>/dev/null; then
echo -e "${GREEN}✓ MCP servers listed successfully${NC}"
else
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MCP server listing test could provide more useful diagnostic information. Currently it only shows success/failure, but capturing and displaying the actual output would help users understand what servers are detected versus what they expect.

Suggested change
# 4. Test MCP server listing
echo -e "${YELLOW}4. Claude MCP Server List:${NC}"
echo "Running: claude mcp list"
if claude mcp list 2>/dev/null; then
echo -e "${GREEN}✓ MCP servers listed successfully${NC}"
else
# 4. Test MCP server listing
echo -e "${YELLOW}4. Claude MCP Server List:${NC}"
echo "Running: claude mcp list"
MCP_OUTPUT=$(claude mcp list 2>&1)
if [[ $? -eq 0 ]]; then
echo -e "${GREEN}✓ MCP servers listed successfully${NC}"
echo " Detected servers:"
echo "$MCP_OUTPUT" | sed 's/^/ /'
else
echo -e "${RED}✗ Failed to list MCP servers${NC}"
echo " Error output:"
echo "$MCP_OUTPUT" | sed 's/^/ /'
fi

Comment on lines +362 to +367

# Clear Claude Code's stale MCP cache to ensure it picks up config changes
# This prevents Claude from reporting removed servers as still available
if [[ -d "$HOME/.claude/statsig" ]]; then
echo "Clearing Claude Code cache to sync MCP server availability..."
rm -rf "$HOME/.claude/statsig"/* 2>/dev/null || true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache clearing logic has a potential issue with the wildcard expansion. If the directory is empty, the rm -rf "$HOME/.claude/statsig"/* command might fail or behave unexpectedly. The current || true handles this, but it would be cleaner to check if files exist first.

Suggested change
# Clear Claude Code's stale MCP cache to ensure it picks up config changes
# This prevents Claude from reporting removed servers as still available
if [[ -d "$HOME/.claude/statsig" ]]; then
echo "Clearing Claude Code cache to sync MCP server availability..."
rm -rf "$HOME/.claude/statsig"/* 2>/dev/null || true
# Clear Claude Code's stale MCP cache to ensure it picks up config changes
# This prevents Claude from reporting removed servers as still available
if [[ -d "$HOME/.claude/statsig" ]]; then
echo "Clearing Claude Code cache to sync MCP server availability..."
if [[ -n "$(ls -A "$HOME/.claude/statsig" 2>/dev/null)" ]]; then
rm -rf "$HOME/.claude/statsig"/* 2>/dev/null || true
echo -e "${GREEN}✓ Claude Code cache cleared${NC}"
else
echo -e "${GREEN}✓ Claude Code cache already empty${NC}"
fi
fi


- [MCP Environment Setup](mcp-environment.md)
- [MCP Client Integration](mcp-client-integration.md)
- [Setting up all MCP servers](../mcp/setup-all-mcp-servers.sh) No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation file lacks a proper file termination with a newline character, which could cause issues with some text processing tools and violates POSIX standards. Files should end with a newline character.

Comment on lines +70 to +75
2. Add configuration to `mcp/mcp.json`:
```json
{
"mcpServers": {
"playwright": { /* existing config */ },
"github": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON configuration example shows environment variable substitution with ${GITHUB_TOKEN}, but it's not clear if this syntax is actually supported by the MCP configuration system. Consider clarifying whether this is literal text that should be replaced manually or if the system supports environment variable expansion.

Suggested change
2. Add configuration to `mcp/mcp.json`:
```json
{
"mcpServers": {
"playwright": { /* existing config */ },
"github": {
2. Add configuration to `mcp/mcp.json`:
```json
{
"mcpServers": {
"playwright": { /* existing config */ },
"github": {
"command": "mcp-server-github",
"args": [],
"env": {
"GITHUB_TOKEN": "your-actual-token-here"
}
}
}
}

Note: Replace "your-actual-token-here" with your actual GitHub token, or use environment variable expansion if supported by your MCP client.

Comment on lines +100 to +102
echo -e "${BLUE}${DIVIDER}${NC}"

echo -e "\n1. To clear potential cache issues:"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache clearing recommendation uses a potentially dangerous wildcard pattern. If ~/.claude/statsig contains unexpected files or subdirectories, this could remove more than intended. Consider using a more targeted approach or adding safety checks.

Suggested change
echo -e "${BLUE}${DIVIDER}${NC}"
echo -e "\n1. To clear potential cache issues:"
echo -e "\n1. To clear potential cache issues:"
echo -e " ${GREEN}# Check what will be removed first:${NC}"
echo -e " ${GREEN}ls -la ~/.claude/statsig/${NC}"
echo -e " ${GREEN}# Then clear the cache:${NC}"
echo -e " ${GREEN}rm -rf ~/.claude/statsig/*${NC}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up tool approval list to match actually available MCP servers

1 participant