Skip to main content
Glama
leo4life2

Minecraft MCP Server

by leo4life2

giveItemToSomeone

Transfer items to another player on a Minecraft server by specifying their username, item name, and quantity. Simplify in-game item sharing with this MCP Server tool.

Instructions

Give items to another player

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
itemCountYesNumber of items to give
itemNameYesName of the item to give
userNameYesUsername of the player to give items to

Implementation Reference

  • The primary handler function for the 'giveItemToSomeone' tool. It validates input parameters, unpacks them, logs the action, and delegates the tossing logic to the tossItemTowardsPlayer helper.
    export const giveItemToSomeone = async (
      bot: Bot,
      params: ISkillParams,
      serviceParams: ISkillServiceParams,
    ): Promise<boolean> => {
      const skillName = 'giveItemToSomeone';
      const requiredParams = ['userName', 'itemName'];
      const isParamsValid = validateSkillParams(
        params,
        requiredParams,
        skillName,
      );
      if (!isParamsValid) {
        serviceParams.cancelExecution?.();
        bot.emit(
          'alteraBotEndObservation',
          `Mistake: You didn't provide all of the required parameters ${requiredParams.join(', ')} for the ${skillName} skill.`,
        );
        return false;
      }
    
      const unpackedParams = {
        playerName: params.userName,
        itemName: params.itemName,
        itemCount: params.itemCount ?? 1,
      };
    
      console.log(
        `Giving ${unpackedParams.itemCount} of ${unpackedParams.itemName} to ${unpackedParams.playerName}`,
      );
      return tossItemTowardsPlayer(bot, {
        playerName: unpackedParams.playerName,
        itemName: unpackedParams.itemName,
        itemCount: unpackedParams.itemCount,
        signal: serviceParams.signal,
      });
    };
  • Core helper function that performs the actual item tossing: validates conditions, moves near the player using pathfinder, looks at the player, and tosses the specified item count using bot.toss().
    export const tossItemTowardsPlayer = async (
      bot: Bot,
      options: ITossItemTowardsPlayerOptions,
    ): Promise<boolean> => {
      const defaultOptions = {
        itemCount: 1,
      };
      const { playerName, itemName, itemCount, signal } = {
        ...defaultOptions,
        ...options,
      };
    
      // max reasonable distance to trade is currently set to same as nearbyPlayerRadius
      const maxGiveDistance = bot.nearbyPlayerRadius;
    
      // Ensure target is a string
      if (typeof playerName !== 'string') {
        return bot.emit(
          'alteraBotEndObservation',
          `Mistake: Invalid playerName: playerName must be a string.`,
        );
      }
    
      const closestItemName = findClosestItemName(bot, { name: itemName });
    
      if (!closestItemName) {
        return bot.emit(
          'alteraBotEndObservation',
          `Mistake: You couldn't give ${itemName} because there's no item named ${itemName} in minecraft.`,
        );
      }
    
      const player = findClosestPlayerByName(bot, { name: playerName });
    
      if (!player) {
        console.log('Player not found!');
        return bot.emit(
          'alteraBotEndObservation',
          `Mistake: The player ${playerName} could not be found.`,
        );
      }
    
      const playerPos = player.position;
      const botPos = bot.entity.position;
      const distanceToPlayer = calculateDistance(botPos, playerPos);
    
      if (distanceToPlayer > maxGiveDistance) {
        bot.emit(
          'alteraBotEndObservation',
          `The player ${playerName} is too far away, you may want to go to their position at ${Math.floor(playerPos.x)}, ${Math.floor(playerPos.y)}, ${Math.floor(playerPos.z)}.`,
        );
        return;
      }
    
      const hasEnough = checkInventoryForItem(bot, closestItemName, itemCount);
      if (!hasEnough) {
        return bot.emit(
          'alteraBotEndObservation',
          `You do not have ${itemCount} of ${closestItemName} to give to ${playerName}.`,
        );
      }
    
      // Stop any existing movement / pathing
      if (bot.pathfinder.isMoving()) {
        await bot.pathfinder.stop();
      }
    
      await bot.waitForTicks(1);
    
      // Create a goal to move near the player
      const maxDistance = 3; // Maximum distance to toss item
      const {
        goals: { GoalNear },
      } = mineflayer_pathfinder;
      const goal = new GoalNear(playerPos.x, playerPos.y, playerPos.z, maxDistance);
      // Move close to the player
      try {
        let reachedGiveTarget = false;
        // start pathfinder to move to the player
        bot.pathfinder.goto(goal).then(() => {
          reachedGiveTarget = true;
        });
    
        // check for a cancel signal during pathing
        // in absolute worst case scenario, the skill will fully time out after 30 seconds
        while (!reachedGiveTarget) {
          if (isSignalAborted(signal)) {
            return bot.emit(
              'alteraBotEndObservation',
              `You decided to do something else instead of giving ${closestItemName}to ${playerName}.`,
            );
          }
    
          await bot.waitForTicks(1);
        }
      } catch (err) {
        const error = err as Error;
        console.log(
          `Failed to reach player in tossItemTowardsPlayer: ${error.message}`,
        );
        return bot.emit(
          'alteraBotEndObservation',
          `You couldn't reach to ${playerName} to give them ${closestItemName}.`,
        );
      }
    
      const itemForToss = bot.inventory
        .items()
        .find((item) => item.name === closestItemName);
      return tossItem(bot, { player, item: itemForToss, itemCount });
    };
  • Schema definition for the giveItemToSomeone tool inputs, including parameter types, descriptions, and required fields used for validation.
    giveItemToSomeone: {
        description: "Give items to another player",
        params: {
            userName: { type: "string", description: "Username of the player to give items to" },
            itemName: { type: "string", description: "Name of the item to give" },
            itemCount: { type: "number", description: "Number of items to give" }
        },
        required: ["userName", "itemName", "itemCount"]
    },
  • The loadSkills function registers the giveItemToSomeone tool (along with others) by iterating over SKILL_METADATA, creating SkillDefinition objects with schema and dynamic executor that imports and runs the handler.
    export async function loadSkills(): Promise<SkillDefinition[]> {
        const skills: SkillDefinition[] = [];
    
        for (const [skillName, metadata] of Object.entries(SKILL_METADATA)) {
            skills.push({
                name: skillName,
                description: metadata.description,
                inputSchema: {
                    type: "object",
                    properties: metadata.params,
                    required: metadata.required
                },
                execute: createSkillExecutor(skillName)
            });
        }
    
        return skills;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. 'Give items' implies a transfer operation that likely requires ownership of items and permission to interact, but the description doesn't disclose behavioral traits such as whether it consumes items from the giver's inventory, requires proximity or online status of the recipient, or has any rate limits or cooldowns. It's minimal and lacks critical context for safe use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste: 'Give items to another player'. It's front-loaded and appropriately sized for the tool's purpose, making it easy to parse without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a mutation tool with 3 parameters. It doesn't cover behavioral aspects like inventory changes, error conditions, or return values. For a tool that modifies game state, more context is needed to ensure correct and safe invocation by an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with clear parameter descriptions (e.g., 'Number of items to give'). The tool description adds no additional meaning beyond the schema, such as explaining item types or user validation. With high schema coverage, the baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Give items to another player' clearly states the action (give) and resource (items), specifying the recipient (another player). It distinguishes from siblings like 'dropItem' or 'pickupItem' by involving transfer to another player, though it doesn't explicitly differentiate from all similar tools like 'sendChat' which might involve communication rather than item transfer.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing items in inventory), exclusions (e.g., cannot give to self), or compare to siblings like 'dropItem' for discarding items or 'sendChat' for communication. Usage is implied but not explicitly defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/leo4life2/minecraft-mcp-http'

If you have feedback or need assistance with the MCP directory API, please join our Discord server