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

Steer for a talent transformation strategy (and avoiding AI fatigue)

 There was a debate on whether to feature the term “AI” in the title of this article. Honestly, a key motivation for pursuing the research that led to this post was sparked by the widespread excitement about AI appearing constantly in our LinkedIn feed, to the point of feeling the fatigue, and even a bit disappointed in the algorithm of this, and the others, social media and content curated apps.  We soon discovered that there is an entire concept called "AI fatigue", not exactly how we were feeling it, but more about the mixed emotions people in the workforce have regarding the use of AI tools. Photo by Mart Production via Pexels (background updated with AI and Adobe  tech) From micro blog posts to video podcasts, lately, most of the tech content we encounter revolves around AI. They often sound or read very similar, usually mentioning the same few top providers. The articles (and social posts... at least the popular ones with paid-campaigns behind it) tend to focus less...

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...

AI Agents is the new thing to talk about

Tech is evolving faster than ever in this AI era, that it feels every week there is something new to talk about, and what you learn weeks back is no longer relevant, or “that AI tools” already has gone through changes that you need to catch up with in order to stay relevant.  Fear not, embrace the challenges and learnings, and find applications for it that are good and ethical for this present, and the hereafter.  The new “craze” is AI agents, and for good reason!  Image generated with NightCafe In contrast with AI chatbots, an AI agent can execute tasks on your behalf. If you are thinking “ that this could be agents that we leave running independently for many days for a group of deliveries ”… Well then you are correct! Are there risks? Should we talk about trust and accountability? The answer for both is yes. I already hinted at it a couple of paragraphs above, when I wrote “ good and ethical ”. AI (Artificial Intelligence) agents are software that work autonomously,...

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