Lesson 3 of 12 intermediate

Tools, MCP and least privilege

MCP হলো tool সংযোগের নিয়ম। এটা নিজে permission বা নিরাপত্তা নিশ্চিত করে না।

Guess first

Pick an answer. You will see if you were right at the end of the lesson.

Can a model choose the tenant it wants?

Open interactive version (quiz + challenge)

Real-world analogy

A standard plug connects equipment; it does not decide who is allowed to use the equipment.

What is it?

A tool has an input schema, an effect and an error contract. MCP standardises context and tool exchange between hosts, clients and servers; your application still owns access decisions. Start with a read-only tool and fixture data.

Real-world relevance

One shared support-ticket product, three optional entry points. Frontend: A design-inspection tool may read components; it must not silently publish a site. Backend: A ticket-read tool enforces tenant ownership using server identity. Mobile: Keep provider credentials off the device; call an authorised backend tool.

Key points

Quick check

Answer from memory — scrolling up first makes it stick less.

What artifact demonstrates this lesson?

Which statement is defensible?

Code example

import json
def parse_read_args(raw):
    value = json.loads(raw)
    if not isinstance(value, dict) or set(value) != {"ticket_id"}:
        raise ValueError("invalid fields")
    if not isinstance(value["ticket_id"], str) or not value["ticket_id"]:
        raise ValueError("invalid ticket id")
    return value["ticket_id"]

Line-by-line walkthrough

  1. 1. Python: JSON parsing and exact fields are only input validation. The actual read handler must separately enforce ticket ownership using authenticated identity.

Spot the bug

read_ticket(ticket_id, tenant_id_from_model)
Need a hint?
Can a model choose the tenant it wants?
Show answer
Use the server session tenant and check ownership for every ticket read.

Explain like I'm 5

MCP হলো tool সংযোগের নিয়ম। এটা নিজে permission বা নিরাপত্তা নিশ্চিত করে না।

Fun fact

A useful artifact for this lesson: Name tools precisely: read_ticket is different from send_reply.

Hands-on challenge

Choose ONE stack; you do not need to build all three. Junior foundation: Validate one read-only tool input and show an invalid input being rejected. Senior extension: Threat-model tool access and demonstrate cross-tenant denial and safe error handling. Evidence: save the input, expected behaviour, actual result and one failure or limitation. Junior means basic coding and Git, not zero programming experience.

More resources

Open interactive version (quiz + challenge) Download the whole course as PDF / Word

Lock it in

← Back to course: AI-Assisted Software Engineering