
pixegami/mcp-python-weather
Developer tools이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기
Google 시트에 연결하는 튜토리얼 MCP 프로젝트
개요
이 프로젝트는 mcp 라이브러리를 사용하여 간단한 날씨 서버를 보여줍니다. OpenWeatherMap API를 사용하여 주어진 위치에 대한 실제 기상 데이터를 반환하는 도구를 노출합니다. MCP(Model Context Protocol)는 AI Agent(LLMs)를 사용하여 데이터, 도구 및 서비스에 액세스할 수 있는 범용 표준입니다. 이 경우, 우리는 LLM에 대한 실제 기상 데이터를 수집하는 "서버"를 구축 할 것입니다. 이 프로젝트는 패키지 관리를 위해 uv를 사용합니다. uv를 설치하는 방법에 대한 지침이 여기에 있습니다. 이 프로젝트는 OpenWeatherMap API를 사용하여 실제 기상 데이터를 fetch합니다. 당신은 필요: 1. OpenWeatherMap 2에서 무료 계정 가입 대시보드 3.에서 API 키 받기 환경 변수 설정: MCP 서버를 테스트하려면 다음 명령을 실행하십시오. 그런 다음로드하는 동안 잠시 기다려서 "open inspector with token pre-filled". 브라우저에서 MCP 서버를 테스트할 수 있는 UI를 제공합니다. 우리의 AI 에이전트는이 MCP 도구를 사용하는 방법을 알고 있습니까?
개요(AI 번역)
이 프로젝트는 mcp] 라이브러리를 사용하여 간단한 날씨 서버를 보여줍니다. OpenWeatherMap API를 사용하여 주어진 위치에 대한 실제 기상 데이터를 반환하는 도구를 노출합니다.
MCP(Model Context Protocol)는 AI Agent(LLMs)를 사용하여 데이터, 도구 및 서비스에 액세스할 수 있는 범용 표준입니다. 이 경우, 우리는 LLM에 대한 실제 기상 데이터를 수집하는 "서버"를 구축 할 것입니다.
설정
이 프로젝트는 패키지 관리에 대한 [T1]]를 사용합니다. uv를 설치하는 방법에 대한 지침이 여기에 있습니다.
가상 환경을 활성화:
의존성 설치.
API 키 설정
이 프로젝트는 OpenWeatherMap API를 사용하여 실제 기상 데이터를 fetch합니다. 당신은 필요:
- OpenWeatherMap에서 무료 계정 가입
- 대시보드에서 API 키 받기
- 환경 변수 설정:
실행하는 방법
MCP 서버를 테스트하려면 다음 명령을 실행하십시오.
그런 다음로드하는 동안 잠시 기다려서 “open inspector with token pre-filled”. 브라우저에서 MCP 서버를 테스트할 수 있는 UI를 제공합니다.
딥 다이브
우리의 AI 에이전트는이 MCP 도구를 사용하는 방법을 알고 있습니까? 글쎄, 간단히 말해서 JSON schema로 일련화됩니다.
이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.
README
원문 README의 일부입니다. 원문 보기.
Python Simple MCP Tutorial
This project demonstrates a simple weather server using the mcp library. It exposes a tool that returns real weather data for a given location using the OpenWeatherMap API.
MCP (Model Context Protocol) is a universal standard that enables AI agents (LLMs) to access data, tools and services. In this case, we will build a “server” that fetches real weather data for an LLM to interact with.
Setting Up
This project uses uv for package management. Go here for instructions on how to install uv.
uv venv
Activate the virtual environment:
source .venv/bin/activate
Install dependencies.
uv sync
API Key Setup
This project uses the OpenWeatherMap API to fetch real weather data. You’ll need to:
- Sign up for a free account at OpenWeatherMap
- Get your API key from the dashboard
- Set the environment variable:
export OPENWEATHER_API_KEY=your_api_key_here
How To Run
To test the weather MCP server, execute the following command:
mcp dev src/mcp_weather.py
Then wait a while for to load, and click the link to “open inspector with token pre-filled”. This will give you a UI you can use to test the MCP server right in your browser.
Deep Dive
How does our AI agent know how to use this MCP tool? Well, in short, it gets serialized into a JSON schema.
FastMCP automatically registers the get_weather function as a tool, extracting the schema from the function signature and docstring.
{
"name": "get_weather",
"description": "Get current weather for a location",
"inputSchema": {
"type": "object",
"properties": {
"location": { "type": "string" }
},
"required": ["location"]
}
}
Then, the AI agent that we use (e.g. Claude Desktop, Cursor, or our own implementation) will know about these tools and know how to invoke them via prompt engineering. It will be turned into a prompt similar to this:
You have access to these tools:
- get_weather: Get current weather for a location
To use: {"name": "get_weather", "parameters": {"location": "Tokyo"}}
MCP Clients: Interacting with MCP Servers
If you want your AI agent to interact with MCP servers, you need an MCP client. Some UI tools (Claude Desktop and Cursor) have this built-in for you already. But you can do this programmatically via code as well.
What it usually boils down to is declaring your MCP server in a config file with instructions on how to access it. In the case of Claude Desktop, it looks something like this:
{
"mcpServers": {
"weather": {
"command": "uv",
"args": ["run", "[...]", "/[PATH_TO_PROJECT]/src/mcp_weather.py"],
"env": {
"OPENWEATHER_API_KEY": "your_api_key_here"
}
}
}
}
설치
uvx mcp-google-sheets@latest설정
{
"mcpServers": {
"weather": {
"command": "uv",
"args": ["run", "[...]", "/[PATH_TO_PROJECT]/src/mcp_weather.py"],
"env": {
"OPENWEATHER_API_KEY": "your_api_key_here"
}
}
}
}