Disclosure: I wrote and maintain the open-source project used here (MIT). I also offer paid setup work, linked at the end. Everything below works without paying anyone.

Most "AI lead scoring" demos paste a lead into a chat and ask "is this a good lead?". Ask again tomorrow and you get a different answer. That is fine for brainstorming and terrible for a sales queue.

The fix is to split the job:

  • Your code owns the rule: the same lead always gets the same score, with reasons you can audit.
  • The model owns the language: deciding which tool to call, summarizing, and drafting the follow-up.

The Model Context Protocol (MCP) is the clean seam between those two. In this post we build (well, read) a complete MCP server in 116 lines of plain Node.js: no SDK, no npm install, no API key, no network calls.

Repo: github.com/alborotar/mcp-automation-starter · Live overview: alborotar.github.io/mcp-automation-starter

What the server exposes

Tool Input Output
score_lead email, company, message, employees score 0-100, tier hot/warm/cold, reasons[]
triage_leads array of leads the same leads scored and sorted, plus a hot count
draft_outreach name, company, pain, lang (en/ko), offer subject + body draft for a human to review
to_csv array of row objects CSV text for HubSpot / Google Sheets / Notion import

Two files do all the work: src/tools.js (pure functions) and src/server.js (JSON-RPC over stdio).

Part 1: a scoring rule you can explain to a sales manager

const FREE_MAIL = new Set(['gmail.com', 'naver.com', 'daum.net', 'hanmail.net', 'yahoo.com', 'outlook.com', 'hotmail.com']); const INTENT_WORDS = ['budget', 'urgent', 'asap', 'contract', 'quote', 'pricing', 'demo', '견적', '예산', '도입', '계약', '긴급']; export function scoreLead({ email = '', company = '', message = '', employees = 0 } = {}) { let score = 0; const reasons = []; const domain = String(email).split('@')[1]?.toLowerCase() || ''; if (domain && !FREE_MAIL.has(domain)) { score += 30; reasons.push('business email domain'); } if (company) { score += 10; reasons.push('company provided'); } const n = Number(employees) || 0; if (n >= 200) { score += 30; reasons.push('200+ employees'); } else if (n >= 20) { score += 20; reasons.push('20-199 employees'); } const text = String(message).toLowerCase(); const hits = INTENT_WORDS.filter((w) => text.includes(w)); if (hits.length) { score += Math.min(30, hits.length * 10); reasons.push(`intent keywords: ${hits.join(', ')}`); } score = Math.min(100, score); const tier = score >= 70 ? 'hot' : score >= 40 ? 'warm' : 'cold'; return { score, tier, reasons }; } 

A few design choices worth copying:

  1. Additive points, capped. Four signals (domain, company, size, intent) with fixed weights. Anyone can read it and argue with a number, which is exactly what you want.
  2. Reasons travel with the score. The model never has to invent a justification; it quotes reasons.
  3. Bilingual intent words. Korean inbound forms say 견적 (quote), 예산 (budget), 도입 (adoption), 계약 (contract), 긴급 (urgent). Adding them to the same list means one rule serves both markets. Note that toLowerCase() is harmless for Hangul, so no special casing is needed.
  4. Local free-mail domains. naver.com, daum.net and hanmail.net matter as much in Korea as gmail.com does elsewhere. Edit this set for your market.

Batch triage is just score-then-sort:

export function triageLeads({ leads = [] } = {}) { const scored = leads.map((l) => ({ ...l, ...scoreLead(l) })).sort((a, b) => b.score - a.score); return { leads: scored.map(({ reasons, ...r }) => ({ ...r, reasons: reasons.join('; ') })), hot: scored.filter((l) => l.tier === 'hot').length, }; } 

Joining reasons into a string is deliberate: it keeps the CSV export one row per lead.

Real output for three sample leads:

{ "leads": [ { "email": "mina@acme-logistics.co.kr", "employees": 250, "message": "견적 and pricing for a demo, budget approved", "score": 100, "tier": "hot", "reasons": "business email domain; company provided; 200+ employees; intent keywords: budget, pricing, demo, 견적" }, { "email": "sam@brightdesk.io", "employees": 35, "message": "Need a quote ASAP", "score": 80, "tier": "hot", "reasons": "business email domain; company provided; 20-199 employees; intent keywords: asap, quote" }, { "email": "joe@gmail.com", "message": "just curious", "score": 0, "tier": "cold", "reasons": "" } ], "hot": 2 } 

Part 2: the whole MCP server, no SDK

MCP over stdio is newline-delimited JSON-RPC 2.0. For a tools-only server you need five methods:

export function handle(msg) { const { id, method, params = {} } = msg || {}; const ok = (result) => ({ jsonrpc: '2.0', id, result }); const err = (code, message) => ({ jsonrpc: '2.0', id, error: { code, message } }); if (id === undefined) return null; // notifications (e.g. notifications/initialized) get no reply switch (method) { case 'initialize': return ok({ protocolVersion: params.protocolVersion || '2025-06-18', capabilities: { tools: {} }, serverInfo: { name: 'mcp-automation-starter', version: '1.0.0' } }); case 'ping': return ok({}); case 'tools/list': return ok({ tools: TOOLS.map(({ run, ...t }) => t) }); // strip the function, keep the schema case 'tools/call': { const tool = TOOLS.find((t) => t.name === params.name); if (!tool) return err(-32602, `Unknown tool: ${params.name}`); try { const out = tool.run(params.arguments || {}); return ok({ content: [{ type: 'text', text: JSON.stringify(out, null, 2) }], structuredContent: out, isError: false }); } catch (e) { return ok({ content: [{ type: 'text', text: String(e?.message || e) }], isError: true }); } } default: return err(-32601, `Method not found: ${method}`); } } 

The loop around it is ten lines with node:readline: parse each line, call handle, write the JSON reply plus \n, and answer unparseable input with -32700 Parse error.

Things that bite people the first time:

  • Never console.log to stdout. stdout is the protocol. Log to stderr.
  • Notifications have no id. Replying to notifications/initialized confuses some clients.
  • Tool errors are results, not protocol errors. A bad argument returns isError: true so the model can read it and retry; an unknown tool or method is a JSON-RPC error.
  • Return both content and structuredContent. Older clients read the text copy; newer ones use the structured object.

Each tool is a plain object, so adding one is a single entry:

{ name: 'score_lead', description: 'Score one inbound B2B lead 0-100 and assign hot/warm/cold tier.', inputSchema: { type: 'object', properties: { email: { type: 'string' }, company: { type: 'string' }, message: { type: 'string' }, employees: { type: 'number' } }, required: ['email'] }, run: scoreLead } 

Part 3: EN/KO follow-up drafts (for leads who contacted you)

draft_outreach returns a subject and body template in English or Korean. Two rules I hold myself to, and recommend you do too:

  • It only drafts. The server has no email capability. A human reads, edits and sends.
  • Use it for people who reached out to you (inbound forms, demo requests, existing customers). Unsolicited commercial email is regulated almost everywhere: CAN-SPAM in the US, GDPR/ePrivacy in the EU, and in Korea 정보통신망법 Article 50 requires prior opt-in consent for advertising messages. Scoring is not consent.

The lang switch is an enum in the schema (['en', 'ko']), so the model cannot invent a third language value. The Korean template uses the honorific 님 and a polite closing; adapt both templates to your own voice before using them.

Part 4: CSV that survives Excel and HubSpot

function csvCell(v) { const s = v == null ? '' : String(v); return /[",\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s; } export function toCsv({ rows = [] } = {}) { if (!Array.isArray(rows) || rows.length === 0) return { csv: '' }; const cols = [...new Set(rows.flatMap((r) => Object.keys(r)))]; // union of keys, first-seen order return { csv: [cols.join(','), ...rows.map((r) => cols.map((c) => csvCell(r[c])).join(','))].join('\n') }; } 

Taking the union of keys matters: leads from different forms rarely have identical fields.

Connect it to Claude Desktop or Claude Code

git clone https://github.com/alborotar/mcp-automation-starter cd mcp-automation-starter npm test # unit tests + an end-to-end test that spawns the server over stdio 

Claude Desktop (claude_desktop_config.json):

{ "mcpServers": { "automation": { "command": "node", "args": ["/ABSOLUTE/PATH/src/server.js"] } } } 

Claude Code:

claude mcp add automation -- node /ABSOLUTE/PATH/src/server.js 

Restart the client, then try:

"Triage these 40 inbound leads, draft Korean follow-ups for the hot ones so I can review them, and give me a CSV."

The model calls triage_leads, then draft_outreach once per hot lead with lang: "ko", then to_csv. The scores are identical every run; only the prose varies.

Testing over stdio

Unit-test the pure functions directly. Then add one end-to-end test that spawns node src/server.js, writes initialize → tools/list → tools/call as lines on stdin, and asserts the JSON lines on stdout. That single test catches most "works in my editor, breaks in the client" bugs (stray stdout logging, missing newline, replying to notifications).

Where to take it next

Because every tool is a pure function plus a schema, typical extensions are small: a CRM write (HubSpot/Pipedrive), a Google Sheets append, a Slack "hot lead" ping, or a Notion/Linear task. Keep anything that sends or writes behind an explicit human confirmation.

Useful links