Skip to main content

Building MCP with TypeScript

[PLACEHOLDER]

MCP servers are popular these days. We’ve been researching and exploring a few code repos, some where missing modularity, others just not having pieces that we were looking for… therefore we decided to build our own, simple and foundational that could be a starting point for those trying to solve for the similar things we were… and we decided to share it with the community, via our public github.

mcp-server-host-datasource
MCP host, server,data sources 

 

 Before we start. 

Using Typescript and NodeJS was one of our requirements. This proved somewhat challenging because I don't code as frequently these days due to my leadership responsibilities, and I typically prefer working with C# or Python.

Colleagues in my tech community have been working with their teams on some of their MCPs going the Python route. Therefore, I said, “I guess we are trying the other route” 😊. One of our reasons to go with TypeScript was due to the need of the integration with APIs, and based on the research, it seems that with TS things can be done smoother. 

Before presenting our findings and sharing the code, we would like to acknowledge ServerAvatar. Although we are not deeply familiar with their operations, we appreciate the informative article authored by Suresh Ramani on their website. The article can be found at: Suresh article about MCP via ServerAvatar.

His article and repo provide a good starting point. We'll focus on sharing our findings and skip some explanations, so read their work if you want an introductory overview.

 The findings and code sharing.

At the end of this section, you will find our version of the code. 

Key considerations:

  1. Code easy to read. Instead of putting all in one main file (i.e. server.ts), I placed the tools into separate files (the tools folder) as definitions. They are pulled into the server file, which is the main. 
  2. Test your code. I left one example of a test (leveraging jest). You will see it in the tests folder.
  3. Bring security into your code. Do not place API keys in your code, but in environment variables. In this case you will see the package.json has a dependency of the dotenv. Which then gets called in the server file (code: dotenv.config()), which then can be used within the tools (see how in the weather tools the API key is pulled into it).
  4. I would like to call out (and give some appreciation to) weatherAPI (link here). We used their API to have the weathertool.js call to display the weather info. 
  5. Select the IDE and code assistant that best fit your needs. We use Microsoft Visual Code along with Copilot, which is integrated with Claude and Gemini. These tools are particularly helpful for users who may not be experts in TS.
Hint/learning: A challenging aspect was using the mcp.json file placed in the .vscode folder; when you try to add the MCP in your IDE through the tools, its name does not appear as expected.  There is a trick for it, but I will leave it to you all as part of your own journey 😊.

Finally, here is the code repo. We hope you find it useful and leverage it.  
typescript-mcp repo in github


Update to article

5 Jan:

We added additional code to the repo; in case you enjoy working with postman collections and are looking to integrate them to your features to accelerate and support your API integrations.

Trending posts

Goal setting frameworks for Product Management - OKR and HOSKR

As a business analyst and product manager we often use various frameworks to synthesize and organize our product ideas and goals. I think of frameworks as tools in our product management tool kit which we use depending on the task at hand.  And speaking of goals, OKR is a very popular framework that I often use to set the goals for the products I am managing. However recently I participated the #ProductCon conference hosted by Product School  and I stumbled upon one of the talks in which Rapha Cohen, the CPO at Google Waze introduced a more effective framework for setting product goals. The framework is called HOSKR.  In this post I'll describe both the OKR and HOSKR frameworks in more details using examples. I hope this will provide you, our readers, more practical insights on how to effectively use these frameworks to set your product goals.  OKR OKR stands for O bjectives and K ey R esults. If you are reading this post then you are on our Beolle blog and I am goi...

AGILE For DIGITAL AGENCIES

Introduction Some Digital agencies have a project process where waterfalls still plays a big part of it, and as far as I can tell, the tech team is usually the one suffering as they are at the last part of the chain left with limited budget and time for execution. I do believe that adopting an Agile approach could make a Digital Agency better and faster. In this article I’m presenting you just another point of view of why it make sense looking at Agile Methodology.  Why Agile for a Digital Agency? The Agile movement started in the software development industry, but it has being proven to be useful in others as well. It becomes handy for the type of business that has changing priorities, changing requirements and flexible deliverables. In the Digital Agency of today you need a different mindset. Creative will always play a huge role (“the bread and butter”). But the “big guys” need to understand that without technology there is no Digital Agency. Technical resources ...

Digital Sovereignty in a Polarised World - Data, Cloud Power, and the Search for Trusted Alternatives

 Relationships have deteriorated, with trust diminished to an extent that may preclude restoration. The world, once structured to favour certain regions, has undergone significant shifts; for numerous countries, such advantages never existed. In this polarised reality, stakeholders are re-evaluating alliances, as former partners now often embody the role of "frenemy," thereby threatening freedom. This phenomenon is longstanding, rooted in historical power dynamics. When politics and influence supersede principles of fairness, respect, and integrity, ethical boundaries become blurred. Previously, issues that did not directly affect you would get overlooked out of principle, but current risks necessitate action to safeguard sovereignty. Information has consistently served as a key strategic asset, a trend only intensified by technological advancements that have elevated data as the principal factor. In other words, technology has amplified that, and data is the name of the game...

Assembling MLOps practice - part 2

 Part I of this series, published in May, discussed the definition of MLOps and outlined the requirements for implementing this practice within an organisation. It also addressed some of the roles necessary within the team to support MLOps. Lego Alike data assembly - Generated with Gemini   This time, we move forward by exploring part of the technical stack that could be an option for implementing MLOps.  Before proceeding, below is a CTA to the first part of the article for reference. Assembling an MLOps Practice - Part 1 ML components are key parts of the ecosystem, supporting the solutions provided to clients. As a result, DevOps and MLOps have become part of the "secret sauce" for success... Take me there Components of your MLOps stack. The MLOps stack optimises the machine learning life-cycle by fostering collaboration across teams, delivering continuous integration and depl...

This blog uses cookies to improve your browsing experience. Simple analytics might be in place for pageviews purposes. They are harmless and never personally identify you.

Agreed