Adicionar uma ferramenta Hello
Decore uma função Python para que a IA possa chamá-la.
Adicionar uma ferramenta Hello é uma aula grátis de MCP Academy no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de MCP Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de MCP Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Give Your Server a Skill
A server with no tools is just a shell. A tool is a Python function the AI can call to actually do something for the user. 🛠️
The Magic Decorator
FastMCP exposes a function as a tool with one line: the @mcp.tool() decorator placed right above your function definition.
@mcp.tool()
def hello():
...Write a Normal Function
The body is just Python. No special protocol code, no JSON by hand. You write what the tool should do and return a value.
@mcp.tool()
def hello():
return "Hello from MCP!"Add a Parameter
Tools get more useful with input. Add a parameter and the model can pass a value when it decides to call your tool.
@mcp.tool()
def greet(name):
return "Hello, " + nameType Hints Build the Schema
Add a type hint like name: str and FastMCP turns it into an input schema. The model then knows exactly what kind of value to send.
@mcp.tool()
def greet(name: str) -> str:
return "Hello, " + nameThe Docstring Becomes the Description
Your function's docstring becomes the tool's description. The model reads it to decide when this tool is the right one to use.
@mcp.tool()
def greet(name: str) -> str:
"""Greet a person by name."""
return "Hello, " + nameThe Name Comes from the Function
By default the tool's name is the function name. So def greet publishes a tool the client lists as "greet".
Return Plain Text
For a first tool, just return a string. FastMCP wraps it into the proper MCP result shape so the client receives clean text.
Describe It Well
Good wording matters: a clear description helps the model pick your tool at the right moment. Vague docstrings lead to missed calls.
It Registers Automatically
You never call a register function yourself. Just by decorating it, the tool is registered on your mcp instance and ready to advertise.
Add as Many as You Like
One server can hold many tools. Just decorate each function, and they all show up together when a client asks what's available.
Quick Check
Where does a tool's description come from?
Recap
You added a tool with @mcp.tool(), gave it typed parameters, and let the docstring describe it. Your server can finally do something. Now let's run it! ✨
Perguntas Frequentes
A aula “Adicionar uma ferramenta Hello” é grátis?
Sim — o texto completo de “Adicionar uma ferramenta Hello” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de MCP Academy, atualize para CoddyKit PRO. O curso de MCP Academy inclui 4 aulas no total.
O que vou aprender em “Adicionar uma ferramenta Hello”?
Decore uma função Python para que a IA possa chamá-la. Você pratica MCP Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar MCP Academy?
Nenhuma experiência prévia é necessária. MCP Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.
Quanto tempo leva a aula “Adicionar uma ferramenta Hello”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de MCP Academy?
Sim. Cada aula de MCP Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Criar uma instância FastMCP
- Adicionar uma ferramenta Hello
- Executar o servidor com stdio
- Confirmar carregamento e listagem das ferramentas