Objectiu del bloc
Entendre MCP, provar servidors MCP existents i construir-ne dos de nous connectats a serveis reals. Al final del bloc, cada developer tindrà un MCP server operatiu i connectat al seu entorn de treball.
Conceptes clau
MCP és el USB-C dels models d’IA
Un protocol estàndard perquè qualsevol model parli amb qualsevol sistema, sense que cada banda hagi d’aprendre o saber-ne de l’altre.
Sense MCP: per cada model i cada sistema cal una integració a mida. Copilot sap parlar amb el codi, però no amb Jira, Sentry ni la vostra DB. N×M plugins.
Amb MCP: una sola integració per sistema. Tots els models compatibles l’aprofiten. El server MCP que construïu avui funciona amb Copilot, Claude Code, Cursor, ChatGPT i tot el que vindrà. No és tecnologia propietària.
No és experimental. És l’estàndard.
15.000+ MCP servers públics al GitHub MCP Registry · 97M descàrregues/mes del SDK oficial · Adoptat per Anthropic, OpenAI, GitHub, Microsoft i Google.
Connexió pedagògica amb el Bloc 2
Les Skills del Bloc 2 i MCP funcionen exactament amb el mateix patró: definir un nom, una descripció i un handler. No és un mecanisme nou — és el mateix concepte aplicat a eines externes.
Contingut generalista vs MCP propi — el contrast clau
Contingut generalista de Copilot llegeix HTML d’una URL pública. Text desestructurat, sense control del format, genèric. Útil per explorar contingut públic ràpidament.
MCP server propi retorna JSON estructurat (títol, gènere, episodis, dates). Copilot rep dades precises. Control total, autenticació i lògica de negoci integrades. Quan necessites estructura, autenticació o reutilització.
Nota sobre comptes de GitHub al Taller 1
Distinció important a 3Cat: Copilot Chat usa el compte Enterprise de 3Cat (subscripció). El MCP de GitHub OAuth usa el compte personal (repo públic de la formació). Verificació: Cmd+Shift+P → ‘Accounts: Manage Accounts’.
Maduresa dels SDKs
TypeScript i Python tenen molts més exemples a la comunitat. Java i .NET són oficials i funcionals, però trobareu menys recursos a GitHub. Viable, però amb més investigació prèvia.
✏️ Completar 2 MCP servers sobre APIs de contingut audiovisual
No construïm des de zero — tenim dos repos starter. El 3cat-tvmaze-mcp té la tool search_show() feta; cal completar get_episodes() (endpoint: api.tvmaze.com/shows/:id/episodes — atenció: TVMaze té un rate limit baix i pot retornar 429). El 3cat-wikipedia-mcp té search_article() feta; cal completar get_article_summary() (endpoint: Wikipedia REST API). Un cop completats, la pregunta de prova és: «Quina és la sinopsi de Merlí, i quants episodis va tenir? Combina Wikipedia i TVMaze.»
Comandos i exemples
git clone https://github.com/Formacio-3Cat/3cat-shows-api.git git clone https://github.com/Formacio-3Cat/3cat-wikipedia-mcp git clone https://github.com/Formacio-3Cat/3cat-tvmaze-mcp {
"servers": {
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp"
},
"github-corporation": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp"
},
"3cat-tvmaze": {
"command": "node",
"args": ["./dist/index.js"]
}
}
}
// HTTP remot → GitHub MCP oficial. OAuth automàtic.
// HTTP remot corporatiu → Compte Enterprise de 3Cat.
// STDIO local propi → El server que construïu avui.
{
"repositoris": {
"branca mcp": "https://github.com/Formacio-3Cat/3cat-shows-api/tree/mcp",
"mcp wikipedia": "https://github.com/Formacio-3Cat/3cat-wikipedia-mcp",
"mcp tv-maze": "https://github.com/Formacio-3Cat/3cat-tvmaze-mcp"
}
}
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({
name: "3cat-tvmaze",
version: "0.1.0",
});
server.tool(
"search_show",
"Search for a TV show by name on TVMaze",
{ query: z.string() },
async ({ query }) => {
const res = await fetch(`https://api.tvmaze.com/search/shows?q=${query}`);
const data = await res.json();
return { content: [{ type: "text", text: JSON.stringify(data) }] };
}
);
await server.connect(new StdioServerTransport());
// 1–3: Imports · 4–8: Instanciar · 9–19: Definir tools · 20: Connectar transport
McpServer server = McpServer.builder()
.name("3cat-tvmaze").version("0.1.0").build();
server.addTool("search_show",
"Search for a TV show on TVMaze",
schema -> schema.property("query", String.class).required(),
(params) -> {
String query = params.getString("query");
String resp = HttpClient.newHttpClient()
.send(HttpRequest.newBuilder()
.uri(URI.create("https://api.tvmaze.com/search/shows?q=" + query))
.build(), BodyHandlers.ofString()).body();
return McpResult.text(resp);
});
server.connect(new StdioServerTransport());
var builder = McpServerBuilder.Create()
.WithName("3cat-tvmaze").WithVersion("0.1.0")
.WithTool<TvMazeTools>();
var server = builder.Build();
await server.RunAsync(new StdioTransport());
public class TvMazeTools {
[McpServerTool]
[Description("Search for a TV show on TVMaze")]
public static async Task<string> SearchShow(
[Description("The show name")] string query) {
using var http = new HttpClient();
return await http.GetStringAsync(
$"https://api.tvmaze.com/search/shows?q={query}");
}
}
// Instanciar · Registrar tools (nom + descripció + schema + handler) · Connectar.
// EL MATEIX PATRÓ CONCEPTUAL.
✓ Artefactes que hauries de tenir
- • MCP server `3cat-tvmaze-mcp` completat: `search_show()` + `get_episodes()` funcionals
- • MCP server `3cat-wikipedia-mcp` completat: `search_article()` + `get_article_summary()` funcionals
- • Fitxer `.vscode/mcp.json` configurat al workspace amb els tres servers actius
- • Comprensió del patró Imports → Instanciar → Definir tools → Connectar, aplicable a TS, Java i .NET