Why Femtech Needs Tailored Tech to Build Smarter Health Solutions for Women
Stay updated with the latest content!
Somnio Software Logo
Services
OverviewFull Product DevelopmentProduct DiscoveryStaff Augmentation
About
CompanyFlutter ExpertisePress & NewsCareers
Our work
Industries
Fintech
Healthcare
Education
Fashion
Media & Entertainment
Retail & Ecommerce
Other
Success Cases
Pronti
Pronti
ProWallet
ProWallet
Siigo
Siigo
CAA Club Group of Companies (CCG)
CAA Club Group of Companies (CCG)
Tracer Golf
Tracer Golf
Meet
Meet
Aqilis
Aqilis
View all
Resources
Open SourceTutorials & TalksDownloadables
Somnio Solutions
OverviewE-commerceNews
Blog
Let’s talk

How to Build your first MCP Server in Dart

Learn how to build your first Model Context Protocol (MCP) server in Dart, connect it to Cursor, and create powerful AI-driven integrations.

How to Build your first MCP Server in Dart
Authors
Gianfranco Papa
Gianfranco Papa
CTO & Co-Founder
Technical
N
min read
/
August 14, 2025
Share
Copy post url
linkedin
Facebook
Twitter

In this blog post, we’ll build a Model Context Protocol (MCP) server in Dart using the mcp_dart package. We'll then connect it to an MCP client like Cursor and explore practical use cases that you or your organization can build upon.

The Basics: What is MCP?

First, let’s review the fundamentals.

What’s MCP?

“Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools.” 

Why is MCP Important?

Think of MCP as the USB-C for AI tools. It standardizes how AI assistants connect to tools and data, allowing developers to build an integration once and use it with any MCP-compatible client or model. This approach decouples the “AI brain” (the LLM) from the business logic, improves security by enabling local or controlled access, and makes integrations reusable across teams and products.

What we’ll build

  • A simple Dart MCP server that communicates over stdio.
  • A sample tool that exposes a method with a defined schema and execution logic.
  • An integration with Cursor via the mcp.json file, allowing the agent to call our Dart tool directly from the chat.

Prerequisites

  • Dart SDK installed.
  • Cursor installed.

Let's get started!

1. Create the Dart Project

First, let's create a new Dart console project and add the necessary dependencies. We'll need mcp_dart.

2. Create the basic server

Next, we'll create our stdio server. This means the server will communicate with the client (Cursor) through standard input and standard output, you can see more in detail how this work here.

Create the file bin/mcp_server.dart with the following boilerplate code:

At this point, you have a functional, empty, MCP server. You can run it to confirm everything is set up correctly:

The server will start and wait for a client to connect. Now, let's give it something useful to do.

Defining our first tool

We'll define a tool to get stock information. While this data could be retrieved from an external API, we'll use a hardcoded list for this demo. Let's organize our project with a clean structure:

1. Create the Data model

First, create the Stock model in lib/models/stock.dart. 

2. Create the Data repository

Next, define a repository to handle our data logic in lib/repositories/stock_repository.dart. This abstracts the data source, making it easy to swap our in-memory list for a real database or API later.

3. Add the tool to the server

This is where the magic happens. Let's go back to bin/mcp_server.dart and register our tool.

Notice two key parts:

  • description: This is crucial. The LLM uses this text to determine if the tool can help resolve the user's prompt. Write clear, descriptive summaries for your tools.
  • callback: This function contains the tool's logic. It initializes our repository, fetches the data, and returns it as a CallToolResult containing a JSON.

Plugging the server into Cursor

While we could continue expanding our tool, this is a good time to test what we have.

1. Compile the Server

First, compile the server into a standalone executable. This makes it fast and easy for Cursor to run.

This will generate a file named `mcp_stocks_server` in your project's root directory.

2. Configure Cursor

Cursor registers custom MCP servers using an mcp.json file located in the .cursor directory in your user's home folder (e.g., ~/.cursor/mcp.json).

Open or create this file and add the following:

Replace [PATH_TO_EXECUTABLE] with the absolute path to the mcp_stocks_server file you just compiled.

Save the file and restart Cursor. You should now see your custom stocks tool enabled. The agent will automatically call it when a relevant prompt is detected.

‍

3. Test it!

For debugging, ask the Cursor chat:

“Get stock prices for Apple, Google, and Meta”

You should see the agent use your tool and provide a response based on the data from your server.

This confirms that the LLM successfully called your get_stocks_information tool and processed its output to generate the final message.

Next steps and further improvements

Development mode (JIT)

For faster development, you can run the server with dart run instead of compiling it each time. Just update the command in mcp.json to use the Dart executable and pass your script as an argument.

This uses Dart's Just-In-Time (JIT) compiler. However, for distribution, the Ahead-Of-Time (AOT) compiled executable is recommended because it starts faster, is a self-contained file, and doesn’t require the end-user to have the Dart SDK installed.

Adding parameters

You can make your tools more powerful by accepting parameters using the toolInputSchema property. For instance, you could allow the user to specify a stock ticker and implement a fetchByTicker method in your repository.

Adding resources and prompts

MCP supports more than just tools. You can also provide context to the AI by adding resources (like the contents of a file) or prompts (pre-defined instructions for the AI).

Conclusions

And there you have it! You've successfully built your first MCP server in Dart and wired it directly into your AI assistant. What we've accomplished here is more than just a technical demo; it's a blueprint for creating powerful, custom AI integrations. By decoupling the AI from the business logic, you gain control, security, and reusability. I encourage you to take this foundation and run with it, add parameters using toolInputSchema, connect to a real database or a third-party API, and see what amazing tools you can build to supercharge your workflow.

At Somnio Software, we specialize in building innovative, scalable solutions that connect AI tools with real-world data and workflows. Whether you’re looking to prototype a new integration, enhance your existing AI assistant, or explore how MCP can streamline your operations, our team is here to help you bring your vision to life.

Contact us

Stay in the loop!

Receive tech news, software tips, and business insights.
Subscribe to our newsletter!

Thank you! Your submission has been received!
Oops! Something went wrong.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Read next

Culture

Why Femtech Needs Tailored Tech to Build Smarter Health Solutions for Women

Read more
Why Femtech Needs Tailored Tech to Build Smarter Health Solutions for Women
Read more
Flutter News

Flutter updates & news July 2025

Read more
Flutter updates & news July 2025
Read more
Somnio Software Logo
Services
Full Product DevelopmentProduct DiscoveryStaff Augmentation
Our work
IndustriesFintechHealthcareEducationEntertainmentSuccess Cases
About
CompanyFlutter ExpertiseCareersPress & NewsPrivacy PolicyCompany Presentation Brochure
Resources
Open SourceTutorials & TalksDownloadablesBlog
Office
José Ellauri 1142
Montevideo, Uruguay
11300
Contact
hello@somniosoftware.comjobs@somniosoftware.com
(+598) 98 168 142 - Uruguay+1 (786) 726‑1751 - US
Clutch Award Top B2B Company 2022
Clutch Award Top B2B Company 2022Clutch Award Top B2B Company 2022Clutch Award Top B2B Company 2022Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2023Clutch Award Top B2B Company 2022The Manifest Award Top Flutter Developers 2021Clutch Award Top 1000 Companies Global 2022Clutch Award Top B2B Company 2023