DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • Building Intelligent Microservices With Go and AWS AI Services
  • Goose Migrations for Smooth Database Changes
  • Control Your Services With OTEL, Jaeger, and Prometheus

Trending

  • DZone's Article Submission Guidelines
  • Docker Base Images Demystified: A Practical Guide
  • How Large Tech Companies Architect Resilient Systems for Millions of Users
  • The Modern Data Stack Is Overrated — Here’s What Works
  1. DZone
  2. Data Engineering
  3. Databases
  4. Build an MCP Server Using Go to Connect AI Agents With Databases

Build an MCP Server Using Go to Connect AI Agents With Databases

Learn to build an MCP server using Go to connect AI agents with Azure Cosmos DB, enabling seamless database interactions with Go SDK and mcp-go tools.

By 
Abhishek Gupta user avatar
Abhishek Gupta
DZone Core CORE ·
Apr. 29, 25 · Analysis
Likes (2)
Comment
Save
Tweet
Share
2.4K Views

Join the DZone community and get the full member experience.

Join For Free

Like many of you, I have been playing around with Model Context Protocol (MCP). 

To dive in, I built a sample MCP server implementation for Azure Cosmos DB with Go. It uses the Go SDK, and mcp-go as the MCP Go implementation.

This MCP server exposes the following tools for interacting with Azure Cosmos DB:

  • List databases: Retrieve a list of all databases in a Cosmos DB account.
  • List containers: Retrieve a list of all containers in a specific database.
  • Read container metadata: Fetch metadata or configuration details of a specific container.
  • Create container: Create a new container in a specified database with a defined partition key.
  • Add item to container: Add a new item to a specified container in a database.
  • Read item: Read a specific item from a container using its ID and partition key.
  • Execute query: Execute a SQL query on a Cosmos DB container with optional partition key scoping.

Here is a demo (recommend watching at 2x speed) using VS Code Insiders in Agent mode:


How to Run

Shell
 
git clone https://github.com/abhirockzz/mcp_cosmosdb_go
cd mcp_cosmosdb_go

go build -o mcp_azure_cosmosdb main.go


Configure the MCP server:

Shell
 
mkdir -p .vscode

# Define the content for mcp.json
MCP_JSON_CONTENT=$(cat <<EOF
{
  "servers": {
    "CosmosDB Golang MCP": {
      "type": "stdio",
      "command": "$(pwd)/mcp_azure_cosmosdb"
    }
  }
}
EOF
)

# Write the content to mcp.json
echo "$MCP_JSON_CONTENT" > .vscode/mcp.json


Azure Cosmos DB RBAC Permissions and Authentication

  • The user principal you will be using should have permissions (control and data plane) to execute CRUD operations on the database, container, and items.
  • Authentication:
    • Local credentials. Just log in locally using Azure CLI (az login), and the MCP server will use the DefaultAzureCredential implementation automatically.
    • Or, you can set the COSMOSDB_ACCOUNT_KEY environment variable in the MCP server configuration:
JSON
 
{
    "servers": {
      "CosmosDB Golang MCP": {
        "type": "stdio",
        "command": "/Users/demo/mcp_azure_cosmosdb",
        "env": {
          "COSMOSDB_ACCOUNT_KEY": "enter the key"
        }
      }
    }
  }


You are good to go! Now, spin up VS Code Insiders in Agent Mode, or any other MCP tool (like Claude Desktop), and try this out!

Local Dev/Testing

MCP inspector

Start with the MCP inspector: 

  • npx @modelcontextprotocol/inspector ./mcp_azure_cosmosdb

MCP, MCP Everywhere!

MCP everywhere

While this is not an "official" Cosmos DB MCP server, I really wanted to try MCP with Go and also demonstrate the Go SDK for Azure Cosmos DB. Win-win! After all, why should Pythonistas have all the fun? Huge props to the creator of the mcp-go project, Ed Zynda! MCP (at the moment) does not have an "official" Go SDK (yeah, I know, shocking, right!). But there are discussions going on, and I encourage all Gophers to chime in!

MCP is touted as the next big thing in the agentic app landscape. Let's see how that goes. In the meantime, keep building stuff and trying out new things. Try out the MCP server and let me know how it goes!

AI Cosmos DB Database Go (programming language)

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Evolution of Cloud Services for MCP/A2A Protocols in AI Agents
  • Building Intelligent Microservices With Go and AWS AI Services
  • Goose Migrations for Smooth Database Changes
  • Control Your Services With OTEL, Jaeger, and Prometheus

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: