MCP ExplorerExplorer

Mcp Vs Function Calling

@andrelandgrafon 9 months ago
8 MIT
FreeCommunity
AI Systems
Explaining MCP by comparing it to function calling

Overview

What is Mcp Vs Function Calling

mcp-vs-function-calling is a project that illustrates the differences between LLM function calling and the Model Context Protocol (MCP). It showcases how MCP builds upon traditional function calling to enhance AI interactions with third-party services.

Use cases

Use cases for mcp-vs-function-calling include controlling smart home devices like lights through voice commands, integrating AI assistants with various APIs, and enhancing user interactions in applications that require real-time data processing.

How to use

To use mcp-vs-function-calling, you can explore the two examples provided: the ‘/func-calling’ CLI app that utilizes OpenAI’s function calling to manage Home Assistant lights, and the ‘/mcp-server’ Node.js application that exposes a ‘control_lights’ function via the MCP protocol.

Key features

Key features of mcp-vs-function-calling include the ability to bridge AI applications with third-party services through standardized protocols, the ease of invoking functions in a controlled manner, and the demonstration of practical applications such as controlling smart home devices.

Where to use

mcp-vs-function-calling can be used in various fields including home automation, AI development, and any application that requires integration between AI models and external services.

Content

Function Calling vs MCP Server

This repository is meant to illustrate the difference between LLM function calling and the Model Context Protocol (MCP).
Function calling has been around for a while, while MCP is a newer standardization attempt.
Comparing the two approaches showcases the value of MCP and how it builds on top of function calling.

This repository contains two examples:

  • /func-calling: CLI app using OpenAI’s function calling to control Home Assistant lights
  • /mcp-server: Node.js MCP server exposing a control_lights function to LLMs that use the MCP protocol

Want to see it in action? Check out my walkthrough on YouTube: MCP vs. Function Calling - Controlling my office lights with Cursor

Home Assistant

Home Assistant is an open-source home automation platform. I run it on a Raspberry Pi in my home.
Home Assistant controls my lights, and you can control it via the Home Assistant WebSocket API.

I built out the ./data-manager and ./hass-ws-client utils while playing around with Home Assistant a while ago. I thought it would be a fun example for an external tool. However, the Home Assistant code isn’t the focus of this repository.

Function Calling

OpenAI function calling docs

Function calling lets AI assistants invoke predefined functions or tools. These functions run directly in the assistant’s environment and can do anything from file searches to API calls. The LLM receives function descriptions in JSON format and specifies which function to call with what arguments. The application then handles the execution.

-> Functions live in your LLM application code.

MCP Server

MCP docs

MCP servers bridge AI applications with third-party services. They expose functions through a standardized protocol that any MCP-compatible LLM can use. While function calling happens locally, MCP servers handle external service communication, auth, and command execution separately.

-> MCP servers are standalone apps any MCP-compatible LLM can use.

Setting up the MCP server

  1. Create a .env file in the mcp-server directory:
cp mcp-server/.env.example mcp-server/.env
  1. Add your Home Assistant API token to the .env file:
HOME_ASSISTANT_API_TOKEN=<your-home-assistant-api-token>
  1. Build the MCP server:
bun i
bun run build
  1. Add the MCP server to your LLM app config (e.g., Cursor):
{
  "name": "home-assistant",
  "command": "node /Users/andrelandgraf/workspaces/mcps/mcp-server/dist/index.js"
}

That’s it! Your LLM app can now control Home Assistant lights through the MCP server.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers