Skip to main content
Glama
smn2gnt

MCP Salesforce Connector

by smn2gnt

get_object_fields

Retrieve field names, labels, and types for a specific Salesforce object using this tool. Simplifies data understanding and integration by providing essential object metadata.

Instructions

Retrieves field Names, labels and types for a specific Salesforce object

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
object_nameYesThe name of the Salesforce object (e.g., 'Account', 'Contact')

Implementation Reference

  • Core implementation of get_object_fields: fetches object metadata from Salesforce, filters and caches fields (label, name, type, etc.), returns formatted JSON.
    def get_object_fields(self, object_name: str) -> str:
        """Retrieves field Names, labels and typesfor a specific Salesforce object.
    
        Args:
            object_name (str): The name of the Salesforce object.
    
        Returns:
            str: JSON representation of the object fields.
        """
        if not self.sf:
            raise ValueError("Salesforce connection not established.")
        if object_name not in self.sobjects_cache:
            sf_object = getattr(self.sf, object_name)
            fields = sf_object.describe()['fields']
            filtered_fields = []
            for field in fields:
                filtered_fields.append({
                    'label': field['label'],
                    'name': field['name'],
                    'updateable': field['updateable'],
                    'type': field['type'],
                    'length': field['length'],
                    'picklistValues': field['picklistValues']
                })
            self.sobjects_cache[object_name] = filtered_fields
            
        return json.dumps(self.sobjects_cache[object_name], indent=2)
  • JSON Schema definition for the tool input: requires 'object_name' string parameter.
    types.Tool(
        name="get_object_fields",
        description="Retrieves field Names, labels and types for a specific Salesforce object",
        inputSchema={
            "type": "object",
            "properties": {
                "object_name": {
                    "type": "string",
                    "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')",
                },
            },
            "required": ["object_name"],
        },
    ),
  • MCP server tool dispatch handler: validates input, calls SalesforceClient.get_object_fields, formats response as TextContent.
    elif name == "get_object_fields":
        object_name = arguments.get("object_name")
        if not object_name:
            raise ValueError("Missing 'object_name' argument")
        if not sf_client.sf:
            raise ValueError("Salesforce connection not established.")
        results = sf_client.get_object_fields(object_name)
        return [
            types.TextContent(
                type="text",
                text=f"{object_name} Metadata (JSON):\n{results}",
            )
        ]
  • Tool registration via @server.list_tools() decorator, which returns list including get_object_fields tool.
    @server.list_tools()
    async def handle_list_tools() -> list[types.Tool]:
        """
        List available tools.
        Each tool specifies its arguments using JSON Schema validation.
        """
        return [
            types.Tool(
                name="run_soql_query",
                description="Executes a SOQL query against Salesforce",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "query": {
                            "type": "string",
                            "description": "The SOQL query to execute",
                        },
                    },
                    "required": ["query"],
                },
            ),
            types.Tool(
                name="run_sosl_search",
                description="Executes a SOSL search against Salesforce",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "search": {
                            "type": "string",
                            "description": "The SOSL search to execute (e.g., 'FIND {John Smith} IN ALL FIELDS')",
                        },
                    },
                    "required": ["search"],
                },
            ),
            types.Tool(
                name="get_object_fields",
                description="Retrieves field Names, labels and types for a specific Salesforce object",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "object_name": {
                            "type": "string",
                            "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')",
                        },
                    },
                    "required": ["object_name"],
                },
            ),
            types.Tool(
                name="get_record",
                description="Retrieves a specific record by ID",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "object_name": {
                            "type": "string",
                            "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')",
                        },
                        "record_id": {
                            "type": "string",
                            "description": "The ID of the record to retrieve",
                        },
                    },
                    "required": ["object_name", "record_id"],
                },
            ),
            types.Tool(
                name="create_record",
                description="Creates a new record",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "object_name": {
                            "type": "string",
                            "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')",
                        },
                        "data": {
                            "type": "object",
                            "description": "The data for the new record",
                            "properties": {},
                            "additionalProperties": True,
                        },
                    },
                    "required": ["object_name", "data"],
                },
            ),
            types.Tool(
                name="update_record",
                description="Updates an existing record",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "object_name": {
                            "type": "string",
                            "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')",
                        },
                        "record_id": {
                            "type": "string",
                            "description": "The ID of the record to update",
                        },
                        "data": {
                            "type": "object",
                            "description": "The updated data for the record",
                            "properties": {},
                            "additionalProperties": True,
                        },
                    },
                    "required": ["object_name", "record_id", "data"],
                },
            ),
            types.Tool(
                name="delete_record",
                description="Deletes a record",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "object_name": {
                            "type": "string",
                            "description": "The name of the Salesforce object (e.g., 'Account', 'Contact')",
                        },
                        "record_id": {
                            "type": "string",
                            "description": "The ID of the record to delete",
                        },
                    },
                    "required": ["object_name", "record_id"],
                },
            ),
            types.Tool(
                name="tooling_execute",
                description="Executes a Tooling API request",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "action": {
                            "type": "string",
                            "description": "The Tooling API endpoint to call (e.g., 'sobjects/ApexClass')",
                        },
                        "method": {
                            "type": "string",
                            "description": "The HTTP method (default: 'GET')",
                            "enum": ["GET", "POST", "PATCH", "DELETE"],
                            "default": "GET",
                        },
                        "data": {
                            "type": "object",
                            "description": "Data for POST/PATCH requests",
                            "properties": {},
                            "additionalProperties": True,
                        },
                    },
                    "required": ["action"],
                },
            ),
            types.Tool(
                name="apex_execute",
                description="Executes an Apex REST request",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "action": {
                            "type": "string",
                            "description": "The Apex REST endpoint to call (e.g., '/MyApexClass')",
                        },
                        "method": {
                            "type": "string",
                            "description": "The HTTP method (default: 'GET')",
                            "enum": ["GET", "POST", "PATCH", "DELETE"],
                            "default": "GET",
                        },
                        "data": {
                            "type": "object",
                            "description": "Data for POST/PATCH requests",
                            "properties": {},
                            "additionalProperties": True,
                        },
                    },
                    "required": ["action"],
                },
            ),
            types.Tool(
                name="restful",
                description="Makes a direct REST API call to Salesforce",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "path": {
                            "type": "string",
                            "description": "The path of the REST API endpoint (e.g., 'sobjects/Account/describe')",
                        },
                        "method": {
                            "type": "string",
                            "description": "The HTTP method (default: 'GET')",
                            "enum": ["GET", "POST", "PATCH", "DELETE"],
                            "default": "GET",
                        },
                        "params": {
                            "type": "object",
                            "description": "Query parameters for the request",
                            "properties": {},
                            "additionalProperties": True,
                        },
                        "data": {
                            "type": "object",
                            "description": "Data for POST/PATCH requests",
                            "properties": {},
                            "additionalProperties": True,
                        },
                    },
                    "required": ["path"],
                },
            ),
        ]
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/smn2gnt/MCP-Salesforce'

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