This repository provides a VS Code Web environment for building custom MCP (Model Context Protocol) tools that can be consumed by AI Foundry agents. If you're using this locally or in your own development environment, check out the Quickstart section below.
To use this sample locally on your machine:
-
Clone the repository:
git clone <repository-url> cd build-custom-tool-with-code
-
Open in VS Code:
code . -
Sign in to Azure and initialize azd:
az login azd auth login
-
Create a new azd project environment, specifying a location (westus2 is recommended), the subscription ID you want to use, and a name for the environment:
azd env new {ENVIRONMENT_NAME} --location westus2 --subscription {SUBSCRIPTION_ID} -
Set up environment variables:
azd env set {VARIABLE}(Note: Specific variables will be defined here later)
(TBD - Codespace setup instructions will be added here)
Create, test and deploy a tool for your AI Foundry agent to consume.
Check out and test the sample tool. You can open and edit your project files from the Explorer view on the left, or proceed with onboarding tasks below.
- From the Explorer view, open the
/srcfolder and selectfunction_app.py - Familiarize yourself with the programming model to build a custom tool that is called through the model-context protocol (MCP).
Press Run to start your local host, and test your tool in the Agent Playground by asking, "what's 9 + 10?".
- From the
/srcfolder, runfunc startto run the MCP server on the localhost. - From
/.vscode/mcp.json, ensure thatlocal-tool-serveris started. - Open chat and select Agent mode with any model.
- Test the sample tools with any of the following prompts:
- "Hello, my name is {YOUR_NAME}"
- "What's 9 + 10?"
- "What's the weather in Seattle today?"
Modify the sample tool with your custom code. To test your iteration, press Run to restart the local host with your latest changes.
The scaffolded project is designed to be hosted on Azure Functions. It uses the MCP Tool Trigger to abstract the complexity of building a full-fledged remote MCP server. If you're new to building serverless applications on Azure Functions, you can refer to APPENDIX: Best practices for building serverless MCP tools.
- After you've modified the sample tool into your desired custom tool, repeat the same steps to iteratively test it.
- From the
/srcfolder, runfunc startto restart the MCP server running on local host with your latest changes. - From
/.vscode/mcp.json, ensure thatlocal-tool-serveris started. - Open chat and select Agent mode with any model.
- Test your custom tool with the appropriate prompts.
Once you're done writing and testing your tool, you can deploy it to Azure using Azure Developer CLI (azd). This will provision an Azure Function app and your project will be deployed to it. Your Foundry agent will be configured to authenticate with the tool.
- From the root directory, run
azd up.
After a successful deployment, your Foundry agent can now call your custom tool. You may exit now, but you can download a copy of the code or push it to a GitHub repository to edit your tool later.
- To save locally, open the command palette (CTRL/CMD+SHIFT+P) and search for
Workspaces: Save Workspace As... - To push to GitHub, open the command palette (CTRL/CMD+SHIFT+P) and search for
Publish to GitHub
Congratulations on building your custom tool with code. You may exit the VS Code for the Web environment and test your custom tool from the Foundry Agent Builder.
When building serverless MCP tools with Azure Functions, consider the following best practices:
(TBD - Best practices will be added later)
- remote-mcp-functions-python - Learn more about the underlying technology powering the remote MCP server and get detailed getting started instructions.