Skip to content

Fix log_level variable name in server.py#2

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-1
Draft

Fix log_level variable name in server.py#2
Copilot wants to merge 2 commits intomainfrom
copilot/fix-1

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2025

This PR fixes the issue where the program throws an exception when running the mcp-get-weather command.

Issue

The error occurs in the logging configuration where the code was trying to access a variable named loglevel which doesn't exist. The error message was:

Traceback (most recent call last):
  File "/root/miniconda3/bin/mcp-get-weather", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/root/miniconda3/lib/python3/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  ...
  File "/root/autodl-tmp/MCP/copilot-test/src/mcp_get_weather/server.py", line 80, in main
    level=getattr(logging, loglevel.upper()),
                           ^^^^^^^^

Fix

The main function defines a parameter called log_level (with an underscore), but was incorrectly trying to use a variable called loglevel (without the underscore) in the logging configuration. The fix was to change the variable name in the logging configuration to match the parameter name:

# Before:
level=getattr(logging, loglevel.upper()),

# After:
level=getattr(logging, log_level.upper()),

Testing

Verified that the command now runs correctly without throwing the exception, and the server starts up properly.

Fixes #1.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: Hsail <25000162+Hsail@users.noreply.github.com>
Copilot AI changed the title [WIP] Bug: 程序在运行 mcp-get-weather 命令时抛出异常并终止执行 Fix log_level variable name in server.py May 20, 2025
Copilot AI requested a review from Hsail May 20, 2025 16:59
Copilot finished work on behalf of Hsail May 20, 2025 16:59
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.

Bug: 程序在运行 mcp-get-weather 命令时抛出异常并终止执行

2 participants